Bug 465014 - Exception during marshalling map adapter.
Summary: Exception during marshalling map adapter.
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-20 08:49 EDT by Iaroslav Savytskyi CLA
Modified: 2022-06-09 10:14 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Iaroslav Savytskyi CLA 2015-04-20 08:49:47 EDT
To work with Map adapter was created. It works fine with JAXB RI, but fails with MOXy: 

Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field MapEntry.key to [LMapEntry;

@XmlRootElement
public class Foo {
    @XmlJavaTypeAdapter(MapAdapter.class)
    public Map<String, Object> map;
}

public class MapAdapter extends XmlAdapter<MapEntry[], Map<String, Object>> {
    @Override
    public Map<String, Object> unmarshal(MapEntry[] v) throws Exception {
        Map<String, Object> map = new HashMap<>();
        for (MapEntry me : v)
            map.put(me.key, me.value);
        return map;
    }
    @Override
    public MapEntry[] marshal(Map<String, Object> v) throws Exception {
        MapEntry[] mes = new MapEntry[v.size()];
        int i = 0;
        for (Map.Entry<String, Object> entry : v.entrySet())
            mes[i++] = new MapEntry(entry.getKey(), entry.getValue());
        return mes;
    }
}

public class MapEntry {
    public String key;
    public Object value;

    public MapEntry() {}

    public MapEntry(String key, Object value) {
        this.key = key;
        this.value = value;
    }
}
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:10:25 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:14:32 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink