JAXB, Custom bindings, Adapter1.class and Joda-time

前端 未结 7 1684
时光说笑
时光说笑 2021-01-11 15:38

I have a problem with the way JAXB is generating the bound classes for an XML schema (which, for sake of precision, I cannot modify). I want to map a xsd:date type to a Joda

7条回答
  •  余生分开走
    2021-01-11 16:01

    You do not need to extend XmlAdapter.

    Just create static methods on a POJO and it will work.

    Example:

     public class DateAdapter {
        private static DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
    
        public static LocalDate unmarshal(String v) throws Exception {
            return fmt.parseLocalDate(v);
        }
    
        public static String marshal(LocalDate v) throws Exception {
            return v.toString("yyyyMMdd");
        }
     }
    

提交回复
热议问题