jaxb从xml文件读取特殊格式日期
步骤:
1。在日期字段中添加注解:@XmlJavaTypeAdapter(DateAdapter.class),该DateAdaper继承XmlAdapter类
如
public class DateAdapter extends XmlAdapter<String, Date> {private SimpleDateFormat yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");@Overridepublic Date unmarshal(String v) throws Exception {return yyyyMMddHHmmss.parse(v);}@Overridepublic String marshal(Date v) throws Exception {return yyyyMMddHHmmss.format(v);}}