jackson cleanup
This commit is contained in:
parent
524e05de83
commit
f1fc00a157
|
@ -1,15 +1,15 @@
|
|||
package org.baeldung.jackson.field;
|
||||
|
||||
public class MyDtoSetter {
|
||||
public class MyDtoWithSetter {
|
||||
|
||||
private int intValue;
|
||||
public boolean booleanValue;
|
||||
|
||||
public MyDtoSetter() {
|
||||
public MyDtoWithSetter() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MyDtoSetter(final int intValue, final boolean booleanValue) {
|
||||
public MyDtoWithSetter(final int intValue, final boolean booleanValue) {
|
||||
super();
|
||||
|
||||
this.intValue = intValue;
|
||||
|
@ -22,7 +22,7 @@ public class MyDtoSetter {
|
|||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
public int alternativeGetIntValue() {
|
||||
public int accessIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import static org.junit.Assert.assertThat;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.baeldung.jackson.field.MyDtoAccessLevel;
|
||||
import org.baeldung.jackson.field.MyDtoSetter;
|
||||
import org.baeldung.jackson.field.MyDtoWithSetter;
|
||||
import org.baeldung.jackson.field.MyDtoWithGetter;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -62,17 +62,17 @@ public class JacksonFieldUnitTest {
|
|||
final String jsonAsString = "{\"intValue\":1}";
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
final MyDtoSetter dtoObject = mapper.readValue(jsonAsString, MyDtoSetter.class);
|
||||
final MyDtoWithSetter dtoObject = mapper.readValue(jsonAsString, MyDtoWithSetter.class);
|
||||
|
||||
assertNotNull(dtoObject);
|
||||
assertThat(dtoObject.alternativeGetIntValue(), equalTo(1));
|
||||
assertThat(dtoObject.accessIntValue(), equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenDifferentAccessLevels_whenSetterAdded_thenStillNotSerializable() throws IOException {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
final MyDtoSetter dtoObject = new MyDtoSetter();
|
||||
final MyDtoWithSetter dtoObject = new MyDtoWithSetter();
|
||||
|
||||
final String dtoAsString = mapper.writeValueAsString(dtoObject);
|
||||
assertThat(dtoAsString, not(containsString("intValue")));
|
||||
|
|
Loading…
Reference in New Issue