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/10/09 15:24:00 UTC

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

     [ https://issues.apache.org/jira/browse/ISIS-1972?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andi Huber closed ISIS-1972.
----------------------------
    Resolution: Fixed

We do now provide JAXB XmlAdapters for Java built-in temporal types in 'applib'

{code:java}
org.apache.isis.applib.adapters.JaxbAdapters
{code}


> 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
>            Assignee: Andi Huber
>            Priority: Major
>             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)