serrutom
asked on
Create a custom binder for Jaxb
I have an XML file I want to parse into an object with Jaxb. I have created the objects according to the XML file I receive, and annotated the getters to setup the binding.
The purchase date is coming in as a yyyyMMdd format, and this is not parsed correctly. I searched around a bit, and it seems I need to create a custom Jaxb binder.
Can anyone give me a jump-start on how i need to create this custom binder ?
Thanks
The purchase date is coming in as a yyyyMMdd format, and this is not parsed correctly. I searched around a bit, and it seems I need to create a custom Jaxb binder.
Can anyone give me a jump-start on how i need to create this custom binder ?
Thanks
@XmlType(name = "PRODUCTSHORT")
public class ProductShort {
private String modelCode;
private String serialNo;
private MyDate purchaseDate;
@XmlElement(name = "MODEL_CODE")
public String getModelCode() {
return modelCode;
}
public void setModelCode(String modelCode) {
this.modelCode = modelCode;
}
@XmlElement(name = "SERIAL_NO")
public String getSerialNo() {
return serialNo;
}
public void setSerialNo(String serialNo) {
this.serialNo = serialNo;
}
@XmlElement(name = "PURCHASE_DATE")
public MyDate getPurchaseDate() {
return purchaseDate;
}
public void setPurchaseDate(MyDate purchaseDate) {
this.purchaseDate = purchaseDate;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I created a MyDateXmlAdapter to convert the incoming date (String) to the MyDate class. And on the MyDate class I added following annotation: @XmlJavaTypeAdapter(MyDate
Open in new window