package com.example; import javax.xml.bind.annotation.XmlRegistry; @XmlRegistry public class ObjectFactory { public ExampleObject createExampleObject() { return new ExampleObject(); } } package com.example; import javax.xml.bind.annotation.adapters.XmlAdapter; import java.text.SimpleDateFormat; import java.util.Date; public class DateAdapter extends XmlAdapter<String, Date> { private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Override public Date unmarshal(String v) throws Exception { return dateFormat.parse(v); } @Override public String marshal(Date v) throws Exception { return dateFormat.format(v); } } package com.example; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.Date; @XmlRootElement public class ExampleObject { private Date date; @XmlJavaTypeAdapter(DateAdapter.class) public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } }


上一篇:
下一篇:
切换中文