diff --git a/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/types/XmlSeeAlsoForSubtypes195Test.java b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/types/XmlSeeAlsoForSubtypes195Test.java new file mode 100644 index 000000000..df749455a --- /dev/null +++ b/jakarta-xmlbind/src/test/java/com/fasterxml/jackson/module/jakarta/xmlbind/types/XmlSeeAlsoForSubtypes195Test.java @@ -0,0 +1,46 @@ +package com.fasterxml.jackson.module.jakarta.xmlbind.types; + +import jakarta.xml.bind.annotation.XmlSeeAlso; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; +import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.jakarta.xmlbind.ModuleTestBase; + +public class XmlSeeAlsoForSubtypes195Test + extends ModuleTestBase +{ + static class Root195 { + public Base195 element; + + protected Root195() { } + public Root195(Base195 e) { + element = e; + } + } + + @JsonTypeInfo(include = As.WRAPPER_ARRAY, use = Id.SIMPLE_NAME) + @XmlSeeAlso({Sub195A.class, Sub195B.class}) + abstract static class Base195 { } + + static class Sub195A extends Base195 { } + static class Sub195B extends Base195 { } + + /* + /********************************************************** + /* Test methods + /********************************************************** + */ + + private final ObjectMapper MAPPER = getJaxbAndJacksonMapper(); + + // [modules-base#195] + public void testXmlSeeAlso195() throws Exception + { + String json = MAPPER.writeValueAsString(new Root195(new Sub195B())); + assertEquals("{\"element\":[\"Sub195B\",{}]}", json); + Root195 result = MAPPER.readValue(json, Root195.class); + assertEquals(Sub195B.class, result.element.getClass()); + } +} diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/TestJaxbPolymorphic.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/TestJaxbPolymorphic.java index e97df8bd1..76bff2d0b 100644 --- a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/TestJaxbPolymorphic.java +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/TestJaxbPolymorphic.java @@ -77,7 +77,7 @@ static class ContainerForBase // @XmlElement(type=BaseImpl.class, name="baseImpl"), public Base[] stuff; } - + /* /********************************************************** /* Test methods @@ -85,7 +85,7 @@ static class ContainerForBase */ private final ObjectMapper MAPPER = getJaxbMapper(); - + //First a simple test with non-collection field @SuppressWarnings("unchecked") diff --git a/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/XmlSeeAlsoForSubtypes195Test.java b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/XmlSeeAlsoForSubtypes195Test.java new file mode 100644 index 000000000..517fe91f3 --- /dev/null +++ b/jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/XmlSeeAlsoForSubtypes195Test.java @@ -0,0 +1,48 @@ +package com.fasterxml.jackson.module.jaxb.types; + +import javax.xml.bind.annotation.XmlSeeAlso; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; +import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.module.jaxb.BaseJaxbTest; + +public class XmlSeeAlsoForSubtypes195Test + extends BaseJaxbTest +{ + static class Root195 { + public Base195 element; + + protected Root195() { } + public Root195(Base195 e) { + element = e; + } + } + + @JsonTypeInfo(include = As.WRAPPER_ARRAY, use = Id.SIMPLE_NAME) + @XmlSeeAlso({Sub195A.class, Sub195B.class}) + abstract static class Base195 { } + + static class Sub195A extends Base195 { } + static class Sub195B extends Base195 { } + + /* + /********************************************************** + /* Test methods + /********************************************************** + */ + + private final ObjectMapper MAPPER = getJaxbAndJacksonMapper(); + + // [modules-base#195] + public void testXmlSeeAlso195() throws Exception + { + String json = MAPPER.writeValueAsString(new Root195(new Sub195B())); + assertEquals("{\"element\":[\"Sub195B\",{}]}", json); + Root195 result = MAPPER.readValue(json, Root195.class); + assertEquals(Sub195B.class, result.element.getClass()); + } +}