Changes to reduce fields not necessary.
This commit is contained in:
parent
15123d8d5a
commit
c96bdead45
|
@ -3,8 +3,7 @@ package org.baeldung.jackson.field;
|
|||
public class MyDtoGetter {
|
||||
|
||||
private String stringValue;
|
||||
int intValue;
|
||||
public boolean booleanValue;
|
||||
private int intValue;
|
||||
|
||||
public MyDtoGetter() {
|
||||
super();
|
||||
|
@ -15,7 +14,6 @@ public class MyDtoGetter {
|
|||
|
||||
this.stringValue = stringValue;
|
||||
this.intValue = intValue;
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
// API
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.baeldung.jackson.field;
|
|||
public class MyDtoGetterImplicitDeserialization {
|
||||
|
||||
private String stringValue;
|
||||
int intValue;
|
||||
public boolean booleanValue;
|
||||
|
||||
public MyDtoGetterImplicitDeserialization() {
|
||||
|
@ -14,7 +13,6 @@ public class MyDtoGetterImplicitDeserialization {
|
|||
super();
|
||||
|
||||
this.stringValue = stringValue;
|
||||
this.intValue = intValue;
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
|
@ -24,8 +22,4 @@ public class MyDtoGetterImplicitDeserialization {
|
|||
return stringValue;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ public class MyDtoSetter {
|
|||
|
||||
private String stringValue;
|
||||
int intValue;
|
||||
public boolean booleanValue;
|
||||
|
||||
public MyDtoSetter() {
|
||||
super();
|
||||
|
@ -15,7 +14,6 @@ public class MyDtoSetter {
|
|||
|
||||
this.stringValue = stringValue;
|
||||
this.intValue = intValue;
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
// API
|
||||
|
|
|
@ -44,26 +44,24 @@ public class JacksonFieldUnitTest {
|
|||
final String dtoAsString = mapper.writeValueAsString(dtoObject);
|
||||
assertThat(dtoAsString, containsString("stringValue"));
|
||||
assertThat(dtoAsString, not(containsString("intValue")));
|
||||
assertThat(dtoAsString, containsString("booleanValue"));
|
||||
System.out.println(dtoAsString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenDifferentAccessLevels_whenGetterAdded_thenDeserializable() throws JsonProcessingException, JsonMappingException, IOException {
|
||||
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"intValue\":1,\"booleanValue\":\"true\"}";
|
||||
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"booleanValue\":\"true\"}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
final MyDtoGetterImplicitDeserialization dtoObject = mapper.readValue(jsonAsString, MyDtoGetterImplicitDeserialization.class);
|
||||
|
||||
assertNotNull(dtoObject);
|
||||
assertThat(dtoObject.getStringValue(), equalTo("dtoString"));
|
||||
assertThat(dtoObject.getIntValue(), equalTo(1));
|
||||
assertThat(dtoObject.booleanValue, equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenDifferentAccessLevels_whenSetterAdded_thenDeserializable() throws JsonProcessingException, JsonMappingException, IOException {
|
||||
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"intValue\":1,\"booleanValue\":\"true\"}";
|
||||
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"intValue\":1}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
final MyDtoSetter dtoObject = mapper.readValue(jsonAsString, MyDtoSetter.class);
|
||||
|
@ -71,7 +69,6 @@ public class JacksonFieldUnitTest {
|
|||
assertNotNull(dtoObject);
|
||||
assertThat(dtoObject.getStringValue(), equalTo("dtoString"));
|
||||
assertThat(dtoObject.anotherGetIntValue(), equalTo(1));
|
||||
assertThat(dtoObject.booleanValue, equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,7 +80,6 @@ public class JacksonFieldUnitTest {
|
|||
final String dtoAsString = mapper.writeValueAsString(dtoObject);
|
||||
assertThat(dtoAsString, containsString("stringValue"));
|
||||
assertThat(dtoAsString, not(containsString("intValue")));
|
||||
assertThat(dtoAsString, containsString("booleanValue"));
|
||||
System.out.println(dtoAsString);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue