Changes to reduce fields not necessary.

This commit is contained in:
Rachel Shu 2014-07-21 08:05:53 -04:00
parent 15123d8d5a
commit c96bdead45
4 changed files with 3 additions and 17 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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);
}