minor fix
This commit is contained in:
parent
951a83c64d
commit
42b09f3490
|
@ -3,17 +3,17 @@ package org.baeldung.jackson.dtos;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class MyDtoIgnoreUnkown {
|
public class MyDtoIgnoreUnknown {
|
||||||
|
|
||||||
private String stringValue;
|
private String stringValue;
|
||||||
private int intValue;
|
private int intValue;
|
||||||
private boolean booleanValue;
|
private boolean booleanValue;
|
||||||
|
|
||||||
public MyDtoIgnoreUnkown() {
|
public MyDtoIgnoreUnknown() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyDtoIgnoreUnkown(final String stringValue, final int intValue, final boolean booleanValue) {
|
public MyDtoIgnoreUnknown(final String stringValue, final int intValue, final boolean booleanValue) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.stringValue = stringValue;
|
this.stringValue = stringValue;
|
|
@ -7,7 +7,7 @@ import static org.junit.Assert.assertThat;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.baeldung.jackson.dtos.MyDto;
|
import org.baeldung.jackson.dtos.MyDto;
|
||||||
import org.baeldung.jackson.dtos.MyDtoIgnoreUnkown;
|
import org.baeldung.jackson.dtos.MyDtoIgnoreUnknown;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
|
@ -48,7 +48,7 @@ public class JacksonDeserializationUnitTest {
|
||||||
// tests - json with unknown fields
|
// tests - json with unknown fields
|
||||||
|
|
||||||
@Test(expected = UnrecognizedPropertyException.class)
|
@Test(expected = UnrecognizedPropertyException.class)
|
||||||
public final void givenJsonHasUnkownValues_whenDeserializingAJsonToAClass_thenExceptionIsThrown() throws JsonParseException, JsonMappingException, IOException {
|
public final void givenJsonHasUnknownValues_whenDeserializingAJsonToAClass_thenExceptionIsThrown() throws JsonParseException, JsonMappingException, IOException {
|
||||||
final String jsonAsString = "{\"stringValue\":\"a\",\"intValue\":1,\"booleanValue\":true,\"stringValue2\":\"something\"}";
|
final String jsonAsString = "{\"stringValue\":\"a\",\"intValue\":1,\"booleanValue\":true,\"stringValue2\":\"something\"}";
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class JacksonDeserializationUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenJsonHasUnkownValuesButJacksonIsIgnoringUnkownFields_whenDeserializing_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
|
public final void givenJsonHasUnknownValuesButJacksonIsIgnoringUnknownFields_whenDeserializing_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
|
||||||
final String jsonAsString =// @formatter:off
|
final String jsonAsString =// @formatter:off
|
||||||
"{\"stringValue\":\"a\"," +
|
"{\"stringValue\":\"a\"," +
|
||||||
"\"intValue\":1," +
|
"\"intValue\":1," +
|
||||||
|
@ -79,7 +79,7 @@ public class JacksonDeserializationUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenJsonHasUnkownValuesButUnkownFieldsAreIgnoredOnClass_whenDeserializing_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
|
public final void givenJsonHasUnknownValuesButUnknownFieldsAreIgnoredOnClass_whenDeserializing_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
|
||||||
final String jsonAsString =// @formatter:off
|
final String jsonAsString =// @formatter:off
|
||||||
"{\"stringValue\":\"a\"," +
|
"{\"stringValue\":\"a\"," +
|
||||||
"\"intValue\":1," +
|
"\"intValue\":1," +
|
||||||
|
@ -87,7 +87,7 @@ public class JacksonDeserializationUnitTest {
|
||||||
"\"stringValue2\":\"something\"}"; // @formatter:on
|
"\"stringValue2\":\"something\"}"; // @formatter:on
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
final MyDtoIgnoreUnkown readValue = mapper.readValue(jsonAsString, MyDtoIgnoreUnkown.class);
|
final MyDtoIgnoreUnknown readValue = mapper.readValue(jsonAsString, MyDtoIgnoreUnknown.class);
|
||||||
|
|
||||||
assertNotNull(readValue);
|
assertNotNull(readValue);
|
||||||
assertThat(readValue.getStringValue(), equalTo("a"));
|
assertThat(readValue.getStringValue(), equalTo("a"));
|
||||||
|
|
Loading…
Reference in New Issue