-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aee8e0
commit c73b072
Showing
2 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/com/fasterxml/jackson/failing/ReadWriteOnlyProp935Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.*; | ||
|
||
public class ReadWriteOnlyProp935Test extends BaseMapTest | ||
{ | ||
// for [databind#935], verify read/write-only cases | ||
static class ReadXWriteY { | ||
@JsonProperty(access=JsonProperty.Access.READ_ONLY) | ||
public int x = 1; | ||
|
||
@JsonProperty(access=JsonProperty.Access.WRITE_ONLY) | ||
public int y = 2; | ||
|
||
public void setX(int x) { | ||
throw new Error("Should NOT set x"); | ||
} | ||
|
||
public int getY() { | ||
throw new Error("Should NOT get y"); | ||
} | ||
} | ||
|
||
public static class Pojo935 | ||
{ | ||
private String firstName = "Foo"; | ||
private String lastName = "Bar"; | ||
|
||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) | ||
public String getFullName() { | ||
return firstName + " " + lastName; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String n) { | ||
firstName = n; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String n) { | ||
lastName = n; | ||
} | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Test methods | ||
/********************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
// [databind#935] | ||
public void testReadOnlyAndWriteOnly() throws Exception | ||
{ | ||
String json = MAPPER.writeValueAsString(new ReadXWriteY()); | ||
assertEquals("{\"x\":1}", json); | ||
|
||
ReadXWriteY result = MAPPER.readValue("{\"x\":5, \"y\":6}", ReadXWriteY.class); | ||
assertNotNull(result); | ||
assertEquals(0, result.x); | ||
assertEquals(6, result.y); | ||
} | ||
|
||
public void testReadOnl935() throws Exception | ||
{ | ||
String json = MAPPER.writeValueAsString(new Pojo935()); | ||
Pojo935 result = MAPPER.readValue(json, Pojo935.class); | ||
assertNotNull(result); | ||
} | ||
} |