Menu

#133 XmlBeans and List/Set <-> primitive array mapping

open
nobody
None
5
2008-02-20
2008-02-20
No

Hi folks,
in our project we use Dozer to map Java DTOs <-> XmlBeans, and we ran in a couple of issues with List/Set <-> primitive array mapping.

The DTO is as follows:

public class MyDTO {
private List<BigInteger> myBigIntegerList;
private List<Boolean> myBooleanList;
private Set<Integer> myIntegerSet;

// Getters and setters...
}

in the XmlBean class, these three fields are arrays:

private BigInteger[] myBigIntegerArray;
private boolean[] myBooleanArray;
private int[] myIntegerArray;

*** ISSUE #1 (DTO -> XmlBeans)
myBigIntegerList gets correctly mapped on myBigIntegerArray, but we get a ClassCastException (in MappingProcessor.addOrUpdateToList) when mapping myBooleanList -> myBooleanArray and myIntegerSet -> myIntegerArray (i.e. mapping fails when mapping a List/Set to a primitive array).

Here follows the stacktrace printed by Dozer when it tries to map myBooleanList -> myBooleanArray (the stacktrace for myIntegerSet -> myIntegerArray exactly the same):

SEVERE: Field mapping error -->
MapId: null
Type: bi-directional
Source parent class: com.hp.dto.MyDTO
Source field name: myBooleanList
Source field type: class java.util.ArrayList
Source field value: [true, false, true]
Dest parent class: com.hp.impl.MyXmlBeanDocumentImpl
Dest field name: myXmlBean.booleansArray
Dest field type: [Z
java.lang.ClassCastException: [Z
at net.sf.dozer.util.mapping.MappingProcessor.addOrUpdateToList(MappingProcessor.java:721)
at net.sf.dozer.util.mapping.MappingProcessor.mapListToArray(MappingProcessor.java:635)
at net.sf.dozer.util.mapping.MappingProcessor.mapCollection(MappingProcessor.java:501)
at net.sf.dozer.util.mapping.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:405)
at net.sf.dozer.util.mapping.MappingProcessor.mapFromFieldMap(MappingProcessor.java:309)

*** ISSUE #2 (XmlBeans -> DTO):
myBigIntegerArray -> myBigIntegerList and myBooleanArray -> myBooleanList are OK, but we get a ClassCastException (in MappingProcessor.mapCollection) when mapping myIntegerArray -> myIntegerSet (i.e. mapping fails when mapping a primitive array to a Set).

Here follows the stacktrace printed by Dozer:

SEVERE: Field mapping error -->
MapId: null
Type: bi-directional
Source parent class: com.hp.impl.MyXmlBeanDocumentImpl
Source field name: myXmlBean.integersArray
Source field type: class [I
Source field value: [I@14df764
Dest parent class: com.hp.dto.MyDTO
Dest field name: myIntegerSet
Dest field type: java.util.Set
java.lang.ClassCastException: [I
at net.sf.dozer.util.mapping.MappingProcessor.mapCollection(MappingProcessor.java:512)
at net.sf.dozer.util.mapping.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:405)
at net.sf.dozer.util.mapping.MappingProcessor.mapFromFieldMap(MappingProcessor.java:309)
at net.sf.dozer.util.mapping.MappingProcessor.mapField(MappingProcessor.java:255)

I already have a patch for both these issues, will post it later.

Pierangelo Magli
HP Italy Innovation Center

Discussion


Log in to post a comment.

MongoDB Logo MongoDB