これは例に従った私のコードです:私はマップ内の日付フィールドをフォーマットすることを探していましたが、この例外をスローします:
The object [{birthDate=1963-07-16 00:00:00.0}], of class [class org.hibernate.collection.internal.PersistentMap], could not be converted to [class it.cineca.jaxb.adapter.MyMapType].
例
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public final class MyMapAdapter extends
XmlAdapter<MyMapType,Map<String, Date>> {
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
@Override
public MyMapType marshal(Map<String, Date> arg0) throws Exception {
MyMapType myMapType = new MyMapType();
for(Entry<String, Date> entry : arg0.entrySet()) {
MyMapEntryType myMapEntryType =
new MyMapEntryType();
myMapEntryType.key = entry.getKey();
myMapEntryType.value = dateFormat.parse(entry.getValue().toString());
myMapEntryType.value = entry.getValue();
myMapType.entry.add(myMapEntryType);
}
return myMapType;
}
@Override
public Map<String, Date> unmarshal(MyMapType arg0) throws Exception {
HashMap<String, Date> hashMap = new HashMap<String, Date>();
for(MyMapEntryType myEntryType : arg0.entry) {
hashMap.put(myEntryType.key, myEntryType.value);
}
return hashMap;
}
}
import java.util.Date;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
public class MyMapEntryType {
@XmlAttribute
public String key;
@XmlValue
public Date value;
}
import java.util.ArrayList;
import java.util.List;
public class MyMapType {
public List<MyMapEntryType> entry =
new ArrayList<MyMapEntryType>();
}
これは人結合ファイルです
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="it.model" xml-mapping-metadata-complete="true">
<xml-schema
element-form-default="QUALIFIED"/>
<java-types>
<java-type name="Person" xml-accessor-type="NONE">
<xml-root-element/>
<xml-type prop-order="firstName lastName stringMap "/>
<java-attributes>
nillable="true"/>
<xml-element java-attribute="stringMap" name="string-map" nillable="true"/>
<xml-element java-attribute="dateMap" name="date-map" nillable="true">
<xml-java-type-adapter value="it.cineca.jaxb.adapter.MyMapAdapter" />
</xml-element>
<xml-element java-attribute="positionCurrentSet" name="position-current-set" nillable="true">
<!-- UNLIKELY THIS DOESN'T PRODUCE EMPTY NODE -->
<xml-null-policy xsi-nil-represents-null="true" empty-node-represents-null="true" null-representation-for-xml="EMPTY_NODE" is-set-performed-for-absent-node="true" />
</xml-element>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
どうすれば解決できますか?http://blog.bdoughan.com/2010/07/xmladapter-jaxbs-secret-weapon.htmlの投稿に従ってみまし たが、同じロジックであるバグが見つかりません。