diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue491NoArgCtorDeserRegressionTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue491NoArgCtorDeserRegressionTest.java
index 0686170ab..973f1a3dd 100644
--- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue491NoArgCtorDeserRegressionTest.java
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue491NoArgCtorDeserRegressionTest.java
@@ -1,31 +1,32 @@
package com.fasterxml.jackson.dataformat.xml.failing;
import com.fasterxml.jackson.annotation.*;
+
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.json.JsonMapper;
+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
/**
* Reproduces no default no-arg ctor found deserialization regression introduced to {@link XmlMapper} in 2.12.0.
*
* @see jackson-dataformat-xml issue 491
*/
-public class Issue491NoArgCtorDeserRegressionTest extends XmlTestBase {
-
+public class Issue491NoArgCtorDeserRegressionTest extends XmlTestBase
+{
+ @JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.EXISTING_PROPERTY,
+ property = "type",
+ defaultImpl = DefaultProblem.class,
+ visible = true)
+ @JsonRootName("problem")
interface Problem {
-
String DEFAULT_TYPE = "about:blank";
-
int DEFAULT_STATUS = 500;
-
String getType();
-
int getStatus();
-
}
static class DefaultProblem implements Problem {
@@ -42,7 +43,8 @@ static class DefaultProblem implements Problem {
*
* @see jackson-databind issue 1820
*/
- DefaultProblem(String type, Integer status) {
+ @JsonCreator
+ DefaultProblem(@JsonProperty("type") String type, @JsonProperty("status") Integer status) {
this.type = type != null ? type : Problem.DEFAULT_TYPE;
this.status = status != null ? status : Problem.DEFAULT_STATUS;
}
@@ -56,70 +58,18 @@ public String getType() {
public int getStatus() {
return status;
}
-
- }
-
- @JsonTypeInfo(
- use = JsonTypeInfo.Id.NAME,
- include = JsonTypeInfo.As.EXISTING_PROPERTY,
- property = "type",
- defaultImpl = DefaultProblem.class,
- visible = true)
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
- @JsonRootName("problem")
- interface ProblemMixIn extends Problem {
-
- @Override
- @JsonProperty("type")
- String getType();
-
- @Override
- @JsonProperty("status")
- int getStatus();
-
- }
-
- abstract static class DefaultProblemMixIn extends DefaultProblem {
-
- @JsonCreator
- DefaultProblemMixIn(
- @JsonProperty("type") String type,
- @JsonProperty("status") Integer status) {
- super(type, status);
- throw new IllegalStateException(
- "mix-in constructor is there only for extracting the JSON mapping, " +
- "it should not have been called");
- }
-
- }
-
- static class ProblemModule extends SimpleModule {
-
- @Override
- public void setupModule(SetupContext context) {
- super.setupModule(context);
- registerMixIns(context);
- }
-
- private static void registerMixIns(SetupContext context) {
- context.setMixInAnnotations(DefaultProblem.class, DefaultProblemMixIn.class);
- context.setMixInAnnotations(Problem.class, ProblemMixIn.class);
- }
-
}
- private static final ProblemModule MODULE = new ProblemModule();
-
- private static final ObjectMapper JSON_MAPPER = new ObjectMapper().registerModule(MODULE);
+ private static final ObjectMapper JSON_MAPPER = new JsonMapper();
- private static final XmlMapper XML_MAPPER = (XmlMapper) new XmlMapper().registerModule(MODULE);
+ private static final XmlMapper XML_MAPPER = newMapper();
/**
* Passes on 2.11.4 and 2.12.{0..4}.
*/
- public void test_empty_Problem_JSON_deserialization() throws IOException {
- byte[] problemJsonBytes = "{}".getBytes(StandardCharsets.UTF_8);
- Problem problem = JSON_MAPPER.readValue(problemJsonBytes, Problem.class);
+ public void test_empty_Problem_JSON_deserialization() throws Exception
+ {
+ Problem problem = JSON_MAPPER.readValue("{}", Problem.class);
assertEquals(Problem.DEFAULT_TYPE, problem.getType());
assertEquals(Problem.DEFAULT_STATUS, problem.getStatus());
}
@@ -127,11 +77,15 @@ public void test_empty_Problem_JSON_deserialization() throws IOException {
/**
* Passes on 2.11.4, but fails on 2.12.{0..4}.
*/
- public void test_empty_Problem_XML_deserialization() throws IOException {
- byte[] problemXmlBytes = "".getBytes(StandardCharsets.UTF_8);
- Problem problem = XML_MAPPER.readValue(problemXmlBytes, Problem.class);
+ public void test_empty_Problem_XML_deserialization() throws Exception
+ {
+ Problem problem = XML_MAPPER.readValue(
+ // This WOULD work:
+// "500",
+ // but not missing
+ "",
+ Problem.class);
assertEquals(Problem.DEFAULT_TYPE, problem.getType());
assertEquals(Problem.DEFAULT_STATUS, problem.getStatus());
}
-
}