Skip to content

Commit

Permalink
Fix tests wrt change in "unknown properties" failing in 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 25, 2024
1 parent fb90bb4 commit e09a681
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ static class Bean987 {
public void testUnknownHandlingDefault() throws Exception
{
try {
MAPPER.readValue(new StringReader(JSON_UNKNOWN_FIELD), TestBean.class);
MAPPER.readerFor(TestBean.class)
.with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.readValue(new StringReader(JSON_UNKNOWN_FIELD));
fail("Should not pass");
} catch (UnrecognizedPropertyException jex) {
verifyException(jex, "Unrecognized property \"foo\"");
Expand Down Expand Up @@ -231,14 +233,16 @@ public void testClassWithIgnoreUnknown() throws Exception
*/
public void testClassWithUnknownAndIgnore() throws Exception
{
ObjectReader r = MAPPER.readerFor(ImplicitIgnores.class)
.with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
// should be ok: "a" and "b" ignored, "c" mapped:
ImplicitIgnores result = MAPPER.readValue
("{\"a\":1,\"b\":2,\"c\":3 }", ImplicitIgnores.class);
ImplicitIgnores result = r.readValue
("{\"a\":1,\"b\":2,\"c\":3 }");
assertEquals(3, result.c);

// but "d" is not defined, so should still error
try {
MAPPER.readValue("{\"a\":1,\"b\":2,\"c\":3,\"d\":4 }", ImplicitIgnores.class);
r.readValue("{\"a\":1,\"b\":2,\"c\":3,\"d\":4 }");
fail("Should not pass");
} catch (UnrecognizedPropertyException e) {
verifyException(e, "Unrecognized property \"d\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public void testBeanAsArrayMerging() throws Exception
// and finally with extra, failing
try {
MAPPER.readerForUpdating(input)
.with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.readValue("[9, 8, 14]");
fail("Should not pass");
} catch (MismatchedInputException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.util.*;

import com.fasterxml.jackson.annotation.*;

import tools.jackson.core.*;
import tools.jackson.core.type.TypeReference;

import tools.jackson.databind.*;
import tools.jackson.databind.deser.DeserializationProblemHandler;
import tools.jackson.databind.exc.UnrecognizedPropertyException;
Expand Down Expand Up @@ -135,7 +137,9 @@ static class Bean987 {
public void testUnknownHandlingDefault() throws Exception
{
try {
MAPPER.readValue(new StringReader(JSON_UNKNOWN_FIELD), TestBean.class);
MAPPER.readerFor(TestBean.class)
.with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.readValue(new StringReader(JSON_UNKNOWN_FIELD));
fail("Should not pass");
} catch (UnrecognizedPropertyException e) {
verifyException(e, "Unrecognized property \"foo\"");
Expand Down Expand Up @@ -230,14 +234,17 @@ public void testClassWithIgnoreUnknown() throws Exception
*/
public void testClassWithUnknownAndIgnore() throws Exception
{
ObjectReader r = MAPPER.readerFor(ImplicitIgnores.class)
.with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

// should be ok: "a" and "b" ignored, "c" mapped:
ImplicitIgnores result = MAPPER.readValue
("{\"a\":1,\"b\":2,\"c\":3 }", ImplicitIgnores.class);
ImplicitIgnores result = r.readValue
("{\"a\":1,\"b\":2,\"c\":3 }");
assertEquals(3, result.c);

// but "d" is not defined, so should still error
try {
MAPPER.readValue("{\"a\":1,\"b\":2,\"c\":3,\"d\":4 }", ImplicitIgnores.class);
r.readValue("{\"a\":1,\"b\":2,\"c\":3,\"d\":4 }");
fail("Should not pass");
} catch (UnrecognizedPropertyException e) {
verifyException(e, "Unrecognized property \"d\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public void testBeanAsArrayMerging() throws Exception
// and finally with extra, failing
try {
MAPPER.readerForUpdating(input)
.with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.readValue("[9, 8, 14]");
fail("Should not pass");
} catch (MismatchedInputException e) {
Expand Down

0 comments on commit e09a681

Please sign in to comment.