Skip to content

Commit 706ec1d

Browse files
author
Eugen
committed
Merge pull request eugenp#29 from rachelshu/master
Changes to reduce fields not necessary.
2 parents e42eab8 + c96bdea commit 706ec1d

File tree

4 files changed

+3
-17
lines changed

4 files changed

+3
-17
lines changed

jackson/src/test/java/org/baeldung/jackson/field/MyDtoGetter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
public class MyDtoGetter {
44

55
private String stringValue;
6-
int intValue;
7-
public boolean booleanValue;
6+
private int intValue;
87

98
public MyDtoGetter() {
109
super();
@@ -15,7 +14,6 @@ public MyDtoGetter(final String stringValue, final int intValue, final boolean b
1514

1615
this.stringValue = stringValue;
1716
this.intValue = intValue;
18-
this.booleanValue = booleanValue;
1917
}
2018

2119
// API

jackson/src/test/java/org/baeldung/jackson/field/MyDtoGetterImplicitDeserialization.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
public class MyDtoGetterImplicitDeserialization {
44

55
private String stringValue;
6-
int intValue;
76
public boolean booleanValue;
87

98
public MyDtoGetterImplicitDeserialization() {
@@ -14,7 +13,6 @@ public MyDtoGetterImplicitDeserialization(final String stringValue, final int in
1413
super();
1514

1615
this.stringValue = stringValue;
17-
this.intValue = intValue;
1816
this.booleanValue = booleanValue;
1917
}
2018

@@ -24,8 +22,4 @@ public String getStringValue() {
2422
return stringValue;
2523
}
2624

27-
public int getIntValue() {
28-
return intValue;
29-
}
30-
3125
}

jackson/src/test/java/org/baeldung/jackson/field/MyDtoSetter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ public class MyDtoSetter {
44

55
private String stringValue;
66
int intValue;
7-
public boolean booleanValue;
87

98
public MyDtoSetter() {
109
super();
@@ -15,7 +14,6 @@ public MyDtoSetter(final String stringValue, final int intValue, final boolean b
1514

1615
this.stringValue = stringValue;
1716
this.intValue = intValue;
18-
this.booleanValue = booleanValue;
1917
}
2018

2119
// API

jackson/src/test/java/org/baeldung/jackson/test/JacksonFieldUnitTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,31 @@ public final void givenDifferentAccessLevels_whenGetterAdded_thenSerializable()
4444
final String dtoAsString = mapper.writeValueAsString(dtoObject);
4545
assertThat(dtoAsString, containsString("stringValue"));
4646
assertThat(dtoAsString, not(containsString("intValue")));
47-
assertThat(dtoAsString, containsString("booleanValue"));
4847
System.out.println(dtoAsString);
4948
}
5049

5150
@Test
5251
public final void givenDifferentAccessLevels_whenGetterAdded_thenDeserializable() throws JsonProcessingException, JsonMappingException, IOException {
53-
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"intValue\":1,\"booleanValue\":\"true\"}";
52+
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"booleanValue\":\"true\"}";
5453
final ObjectMapper mapper = new ObjectMapper();
5554

5655
final MyDtoGetterImplicitDeserialization dtoObject = mapper.readValue(jsonAsString, MyDtoGetterImplicitDeserialization.class);
5756

5857
assertNotNull(dtoObject);
5958
assertThat(dtoObject.getStringValue(), equalTo("dtoString"));
60-
assertThat(dtoObject.getIntValue(), equalTo(1));
6159
assertThat(dtoObject.booleanValue, equalTo(true));
6260
}
6361

6462
@Test
6563
public final void givenDifferentAccessLevels_whenSetterAdded_thenDeserializable() throws JsonProcessingException, JsonMappingException, IOException {
66-
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"intValue\":1,\"booleanValue\":\"true\"}";
64+
final String jsonAsString = "{\"stringValue\":\"dtoString\",\"intValue\":1}";
6765
final ObjectMapper mapper = new ObjectMapper();
6866

6967
final MyDtoSetter dtoObject = mapper.readValue(jsonAsString, MyDtoSetter.class);
7068

7169
assertNotNull(dtoObject);
7270
assertThat(dtoObject.getStringValue(), equalTo("dtoString"));
7371
assertThat(dtoObject.anotherGetIntValue(), equalTo(1));
74-
assertThat(dtoObject.booleanValue, equalTo(true));
7572
}
7673

7774
@Test
@@ -83,7 +80,6 @@ public final void givenDifferentAccessLevels_whenSetterAdded_thenStillNotSeriali
8380
final String dtoAsString = mapper.writeValueAsString(dtoObject);
8481
assertThat(dtoAsString, containsString("stringValue"));
8582
assertThat(dtoAsString, not(containsString("intValue")));
86-
assertThat(dtoAsString, containsString("booleanValue"));
8783
System.out.println(dtoAsString);
8884
}
8985

0 commit comments

Comments
 (0)