You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by "Andi Huber (JIRA)" <ji...@apache.org> on 2018/07/22 12:32:00 UTC

[jira] [Created] (ISIS-1972) JAXB view model: add default XmlAdapters for Java 8 Time

Andi Huber created ISIS-1972:
--------------------------------

             Summary: JAXB view model: add default XmlAdapters for Java 8 Time
                 Key: ISIS-1972
                 URL: https://issues.apache.org/jira/browse/ISIS-1972
             Project: Isis
          Issue Type: Improvement
          Components: Core
    Affects Versions: 2.0.0-M1
            Reporter: Andi Huber
             Fix For: 2.0.0-M2


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

sample code:


{code:java}

// 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();
        }

    }

   ...
    
}
{code}






--
This message was sent by Atlassian JIRA
(v7.6.3#76005)