-
-
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.
Merge branch 'master' into tatu/3.0/4891-rm-moditect-add-module-info
- Loading branch information
Showing
2 changed files
with
89 additions
and
25 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/test/java/tools/jackson/databind/deser/filter/ReadOnlyDeser95Test.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,87 @@ | ||
package tools.jackson.databind.deser.filter; | ||
|
||
import java.beans.ConstructorProperties; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import tools.jackson.databind.ObjectMapper; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import static tools.jackson.databind.testutil.DatabindTestUtil.newJsonMapper; | ||
|
||
public class ReadOnlyDeser95Test | ||
{ | ||
// [databind#95] | ||
@JsonIgnoreProperties(value={ "computed" }, allowGetters=true) | ||
static class ReadOnly95Bean | ||
{ | ||
public int value = 3; | ||
|
||
public int getComputed() { return 32; } | ||
} | ||
|
||
static class Person { | ||
public String name; | ||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) | ||
private TestEnum testEnum = TestEnum.DEFAULT; | ||
|
||
Person() { } | ||
|
||
public Person(TestEnum testEnum, String name) { | ||
this.testEnum = testEnum; | ||
this.name = name; | ||
} | ||
|
||
public TestEnum getTestEnum() { | ||
return testEnum; | ||
} | ||
|
||
public void setTestEnum(TestEnum testEnum) { | ||
this.testEnum = testEnum; | ||
} | ||
} | ||
|
||
enum TestEnum{ | ||
DEFAULT, TEST; | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Test methods | ||
/********************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
// [databind#95] | ||
@Test | ||
public void testReadOnlyProps95() throws Exception | ||
{ | ||
ObjectMapper m = new ObjectMapper(); | ||
String json = m.writeValueAsString(new ReadOnly95Bean()); | ||
if (json.indexOf("computed") < 0) { | ||
fail("Should have property 'computed', didn't: "+json); | ||
} | ||
ReadOnly95Bean bean = m.readValue(json, ReadOnly95Bean.class); | ||
assertNotNull(bean); | ||
} | ||
|
||
@Test | ||
public void testDeserializeOneField() throws Exception { | ||
Person person = MAPPER.readValue("{\"testEnum\":\"\"}", Person.class); | ||
assertEquals(TestEnum.DEFAULT, person.getTestEnum()); | ||
assertNull(person.name); | ||
} | ||
|
||
@Test | ||
public void testDeserializeTwoFields() throws Exception { | ||
Person person = MAPPER.readValue("{\"testEnum\":\"\",\"name\":\"changyong\"}", | ||
Person.class); | ||
assertEquals(TestEnum.DEFAULT, person.getTestEnum()); | ||
assertEquals("changyong", person.name); | ||
} | ||
} |
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