Community
Participate
Working Groups
This issue deals with the case where there is a List in the model class, and the adapter has Object as the return type of the marshal method. Note that in this case the adapter is applied to each entry in the list as opposed to the list itself. Given the following model class: @XmlRootElement public class Foo { @XmlElementRef(type=Bar.class) @XmlJavaTypeAdapter(value=MyAdapter.class) public List<String> items; } And the following adapter: public final class MyAdapter extends XmlAdapter<Object, String> { public MyAdapter() {} public String unmarshal(Object arg0) throws Exception { String id = ""; if (arg0 instanceof Bar) { id = ((Bar)arg0).id; } return id; } public Object marshal(String arg0) throws Exception { Bar bar = new Bar(); if (arg0.equals("666")) { bar.id = arg0; } else if (arg0.equals("777")) { bar.id = arg0; } else if (arg0.equals("888")) { bar.id = arg0; } return bar; } } When we try and marshal a Foo we get the following exception: Exception Description: The object [[666, 777, 888]], of class [class java.util.ArrayList], could not be converted to [class java.lang.Object]
Created attachment 185913 [details] Proposed fix
Created attachment 185914 [details] Supporting tests
Reviewed by: matt.macivor@oracle.com Tests: all unit tests pass as expected; jaxb/externalizedmetadata/xmladapter/list/XmlAdapterListTestCases; jaxb/xmladapter/list/XmlAdapterListMultipleBarTestCases; jaxb/xmladapter/list/XmlAdapterListSingleBarTestCases Revision: 8761
Checked in tests cover two use cases for List type with adapter marshal method return type of Object: 1) Adapter applied to each entry in the list 2) Adapter applied to the entire list
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink