Uploaded image for project: 'Isis'
  1. Isis
  2. ISIS-1972

JAXB view model: add default XmlAdapters for Java 8 Time

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-M1
    • Fix Version/s: 2.0.0-M2
    • Component/s: Isis Core
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: