Uploaded image for project: 'Causeway'
  1. Causeway
  2. CAUSEWAY-1972

JAXB view model: add default XmlAdapters for Java 8 Time

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0-M1
    • 2.0.0-M2
    • Core
    • None

    Description

      see https://stackoverflow.com/questions/36156741/marshalling-localdate-using-jaxb

      sample code:

      
      // DOMAIN CODE
      
      @XmlRootElement(name = "Demo")
      @XmlType
      @XmlAccessorType(XmlAccessType.FIELD)
      @DomainObject(nature=Nature.VIEW_MODEL, editing=Editing.ENABLED)
      @Log
      public class TemporalDemo extends DemoStub {
      
          @PostConstruct
          public void initDefaults() {
              
              log.info("TemporalDemo::initDefaults");
              
              javaLocalDate = LocalDate.now();
              javaLocalDateTime = LocalDateTime.now();
          }
          
          @XmlJavaTypeAdapter(value = LocalDateAdapter.class)
          @XmlElement @Getter @Setter private LocalDate javaLocalDate;
          
          @XmlJavaTypeAdapter(value = LocalDateTimeAdapter.class)
          @XmlElement @Getter @Setter private LocalDateTime javaLocalDateTime;
          
      }
      
      // COULD BE PART OF CORE
      
      public final class JaxbAdapters {
      
          
          public static final class LocalDateAdapter extends XmlAdapter<String, LocalDate>{
      
              public LocalDate unmarshal(String v) throws Exception {
                  return LocalDate.parse(v);
              }
      
              public String marshal(LocalDate v) throws Exception {
                  return v.toString();
              }
      
          }
          
          public static final class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime>{
      
              public LocalDateTime unmarshal(String v) throws Exception {
                  return LocalDateTime.parse(v);
              }
      
              public String marshal(LocalDateTime v) throws Exception {
                  return v.toString();
              }
      
          }
      
         ...
          
      }
      

      Attachments

        Activity

          People

            hobrom Andi Huber
            hobrom Andi Huber
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: