You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/01/17 07:09:30 UTC
[isis] branch master updated: ISIS-2877: adds JaxbAdapter for CalendarEvent
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 7075392 ISIS-2877: adds JaxbAdapter for CalendarEvent
7075392 is described below
commit 7075392e55ca222ed2707109004b9c5f70ebb76f
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 17 08:09:19 2022 +0100
ISIS-2877: adds JaxbAdapter for CalendarEvent
---
.../types/isisext/cal/vm/IsisCalendarEventVm.java | 5 +++++
.../fullcalendar/applib/value/CalendarEvent.java | 25 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/types/isisext/cal/vm/IsisCalendarEventVm.java b/examples/demo/domain/src/main/java/demoapp/dom/types/isisext/cal/vm/IsisCalendarEventVm.java
index 2633a9e..283f14d 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/types/isisext/cal/vm/IsisCalendarEventVm.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/types/isisext/cal/vm/IsisCalendarEventVm.java
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.isis.applib.annotation.DomainObject;
import org.apache.isis.applib.annotation.Editing;
@@ -61,22 +62,26 @@ public class IsisCalendarEventVm
@Title(prepend = "CalendarEvent view model: ")
@PropertyLayout(fieldSetId = "read-only-properties", sequence = "1")
@XmlElement(required = true) // <.>
+ @XmlJavaTypeAdapter(CalendarEvent.JaxbAdapter.class)
@Getter @Setter
private CalendarEvent readOnlyProperty;
@Property(editing = Editing.ENABLED) // <.>
@PropertyLayout(fieldSetId = "editable-properties", sequence = "1")
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(CalendarEvent.JaxbAdapter.class)
@Getter @Setter
private CalendarEvent readWriteProperty;
@Property(optionality = Optionality.OPTIONAL) // <.>
@PropertyLayout(fieldSetId = "optional-properties", sequence = "1")
+ @XmlJavaTypeAdapter(CalendarEvent.JaxbAdapter.class)
@Getter @Setter
private CalendarEvent readOnlyOptionalProperty;
@Property(editing = Editing.ENABLED, optionality = Optionality.OPTIONAL)
@PropertyLayout(fieldSetId = "optional-properties", sequence = "2")
+ @XmlJavaTypeAdapter(CalendarEvent.JaxbAdapter.class)
@Getter @Setter
private CalendarEvent readWriteOptionalProperty;
diff --git a/extensions/vw/fullcalendar/applib/src/main/java/org/apache/isis/extensions/fullcalendar/applib/value/CalendarEvent.java b/extensions/vw/fullcalendar/applib/src/main/java/org/apache/isis/extensions/fullcalendar/applib/value/CalendarEvent.java
index 5260b66..2275b06 100644
--- a/extensions/vw/fullcalendar/applib/src/main/java/org/apache/isis/extensions/fullcalendar/applib/value/CalendarEvent.java
+++ b/extensions/vw/fullcalendar/applib/src/main/java/org/apache/isis/extensions/fullcalendar/applib/value/CalendarEvent.java
@@ -24,9 +24,13 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
import org.springframework.lang.Nullable;
import org.apache.isis.applib.IsisModuleApplib;
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.commons.internal.resources._Json;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
@@ -102,4 +106,25 @@ implements
return Long.compare(this.epochMillis, other.getEpochMillis());
}
+ // -- UTILITY
+
+ public static final class JaxbAdapter
+ extends XmlAdapter<String, CalendarEvent> {
+
+ @Override
+ public CalendarEvent unmarshal(final String v) {
+ return _Strings.isNotEmpty(v)
+ ? _Json.readJson(CalendarEvent.class, v).presentElseFail()
+ : null;
+ }
+
+ @Override
+ public String marshal(final CalendarEvent v) {
+ return v!=null
+ ? _Json.toString(v).presentElseFail()
+ : null;
+ }
+
+ }
+
}