Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333166 - MOXy: XmlJavaTypeAdapter not working in collection case when return type of marshal method is Object
Summary: MOXy: XmlJavaTypeAdapter not working in collection case when return type of ...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-23 12:55 EST by David McCann CLA
Modified: 2022-06-09 10:29 EDT (History)
0 users

See Also:


Attachments
Proposed fix (4.24 KB, patch)
2010-12-30 12:37 EST, David McCann CLA
no flags Details | Diff
Supporting tests (66.21 KB, patch)
2010-12-30 12:37 EST, David McCann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David McCann CLA 2010-12-23 12:55:44 EST
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]
Comment 1 David McCann CLA 2010-12-30 12:37:10 EST
Created attachment 185913 [details]
Proposed fix
Comment 2 David McCann CLA 2010-12-30 12:37:46 EST
Created attachment 185914 [details]
Supporting tests
Comment 3 David McCann CLA 2010-12-30 12:46:47 EST
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
Comment 4 David McCann CLA 2010-12-30 12:49:11 EST
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
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:15:45 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:29:30 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink