Skip to content

Commit 3e1b756

Browse files
committed
Minor extension to #650 test
1 parent 476f196 commit 3e1b756

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/test/java/tools/jackson/databind/tofix/UnwrappedWithUnknown650Test.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tools.jackson.databind.testutil.DatabindTestUtil;
1111
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;
1212

13+
import static org.junit.jupiter.api.Assertions.assertEquals;
1314
import static org.junit.jupiter.api.Assertions.fail;
1415

1516
class UnwrappedWithUnknown650Test extends DatabindTestUtil {
@@ -22,20 +23,27 @@ static class B {
2223
public String field;
2324
}
2425

25-
26+
private final ObjectMapper MAPPER = JsonMapper.builder()
27+
.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
28+
.build();
29+
2630
@JacksonTestFailureExpected
2731
@Test
2832
void failOnUnknownPropertyUnwrapped() throws Exception {
29-
final ObjectMapper mapper = JsonMapper.builder()
30-
.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
31-
.build();
3233

33-
final String JSON = "{'field': 'value', 'bad':'bad value'}";
34+
final String JSON = "{'field': 'value', 'bad': 'bad value'}";
3435
try {
35-
mapper.readValue(a2q(JSON), A.class);
36+
MAPPER.readValue(a2q(JSON), A.class);
3637
fail("Exception was not thrown on unknown property");
3738
} catch (UnrecognizedPropertyException e) {
3839
verifyException(e, "Unrecognized property");
3940
}
4041
}
42+
43+
// Passing case, regular usage
44+
@Test
45+
void worksOnRegularPropertyUnwrapped() throws Exception {
46+
A value = MAPPER.readValue(a2q("{'field': 'value'}"), A.class);
47+
assertEquals("value", value.b.field);
48+
}
4149
}

0 commit comments

Comments
 (0)