-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests relating to aspects of #195 (verify @XmlSeeAlso handling wr…
…t subtype deps)
- Loading branch information
1 parent
a45154d
commit a751f9c
Showing
3 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...java/com/fasterxml/jackson/module/jakarta/xmlbind/types/XmlSeeAlsoForSubtypes195Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/types/XmlSeeAlsoForSubtypes195Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |