Details
-
Bug
-
Resolution: Obsolete
-
Major
-
None
-
1.2.RC1
-
None
Description
I have followed the unofficial JAXB guide to attempt to serialize and deserialize a JAXB object that contains a list of an interface type that has multiple implementations. Serializing works fine and as expected. If I attempt to deserialize the JSON object that I serialized in the first step, I do not get a similar JAXB object. The source for the test case is below:
import java.util.*;
import java.io.*;
import javax.xml.transform.stream.*;
import javax.xml.bind.*;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.*;
import org.jboss.resteasy.plugins.providers.jaxb.json.*;
public class TestCase {
@XmlRootElement(namespace = "http://acme.com")
public static class Outer {
@XmlElementWrapper(name = "elems", namespace = "http://acme.com")
@XmlElementRefs(
)
public List<IF> elems;
}
@XmlJavaTypeAdapter(IFAdapter.class)
public static interface IF {
}
public static class IFAdapter extends XmlAdapter<Object, Object> {
@Override
public Object unmarshal(Object v) throws Exception
@Override
public Object marshal(Object v) throws Exception { return v; }
}
@XmlRootElement(namespace = "http://acme.com")
public static class One implements IF
@XmlRootElement(namespace = "http://acme.com")
public static class Two implements IF
public static void main(String argv[]) throws Exception
{ JettisonMappedContext jmctx = new JettisonMappedContext(Collections.singletonMap("http://acme.com", "acme"), null, null, One.class, Two.class, Outer.class); Unmarshaller unmarshaller = jmctx.createUnmarshaller(); Marshaller marshaller = jmctx.createMarshaller(); Outer o = new Outer(); One one = new One(); one.foo = "hello"; Two two = new Two(); two.bar = "world"; List<IF> ifs = new ArrayList<IF>(); ifs.add(one); ifs.add(one); ifs.add(two); o.elems = ifs; StringWriter sw = new StringWriter(); marshaller.marshal(o, sw); String json = sw.getBuffer().toString(); System.out.println(json); Outer output = (Outer) unmarshaller.unmarshal(new StreamSource(new ByteArrayInputStream(json.getBytes()))); System.out.println(output.elems.size()); }}