forked from FasterXML/jackson-dataformat-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add failing test to describe issue FasterXML#230
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/test/java/com/fasterxml/jackson/dataformat/xml/ser/FlatSubtypes230Test.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,69 @@ | ||
package com.fasterxml.jackson.dataformat.xml.ser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Goatfryed | ||
*/ | ||
public class FlatSubtypes230Test { | ||
|
||
public static class Person { | ||
public final List<Hobby> hobbies = new ArrayList<>(); | ||
} | ||
|
||
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value=Reading.class, name = "reading"), | ||
@JsonSubTypes.Type(value=Biking.class, name = "biking") | ||
}) | ||
public interface Hobby { | ||
|
||
} | ||
|
||
public static class Reading implements Hobby { | ||
public final String favoriteBook; | ||
|
||
public Reading(String favoriteBook) { | ||
this.favoriteBook = favoriteBook; | ||
} | ||
} | ||
|
||
public static class Biking implements Hobby { | ||
public final String bikeType; | ||
|
||
public Biking(String bikeType) { | ||
this.bikeType = bikeType; | ||
} | ||
} | ||
|
||
// [dataformat-xml#230] | ||
@Test | ||
public void testFlatSubtypes() throws IOException { | ||
|
||
Person person = new Person(); | ||
person.hobbies.add(new Reading("moby dick")); | ||
person.hobbies.add(new Biking("mountain bike")); | ||
|
||
String actual = new XmlMapper().writeValueAsString(person); | ||
|
||
String expected = "<Person><hobbies>" + | ||
"<reading>" + | ||
"<favoriteBook>moby dick</favoriteBook>" + | ||
"</reading>" + | ||
"<biking>" + | ||
"<bikeType>mountain bike></bikeType>" + | ||
"</biking>" + | ||
"</hobbies></Person>"; | ||
|
||
assertEquals(expected, actual); | ||
} | ||
} |