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/12/14 04:53:39 UTC

[isis] branch master updated: ISIS-3304: JaxbUtils: adding custom properties support

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 ddac408c5d ISIS-3304: JaxbUtils: adding custom properties support
ddac408c5d is described below

commit ddac408c5d9f65208528ad345975888a9c030762
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Dec 14 05:53:32 2022 +0100

    ISIS-3304: JaxbUtils: adding custom properties support
---
 .../java/org/apache/causeway/commons/io/JaxbUtils.java     | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/commons/src/main/java/org/apache/causeway/commons/io/JaxbUtils.java b/commons/src/main/java/org/apache/causeway/commons/io/JaxbUtils.java
index 6c10a345e2..92691b4e99 100644
--- a/commons/src/main/java/org/apache/causeway/commons/io/JaxbUtils.java
+++ b/commons/src/main/java/org/apache/causeway/commons/io/JaxbUtils.java
@@ -47,6 +47,7 @@ import org.apache.causeway.commons.internal.reflection._Annotations;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NonNull;
+import lombok.Singular;
 import lombok.SneakyThrows;
 import lombok.val;
 import lombok.experimental.UtilityClass;
@@ -64,10 +65,13 @@ public class JaxbUtils {
         private final @Builder.Default boolean useContextCache = true;
         private final @Builder.Default boolean allowMissingRootElement = false;
         private final @Builder.Default boolean formattedOutput = false;
+        private final @Singular Map<String, Object> properties;
         public static JaxbOptions defaults() {
             return JaxbOptions.builder().build();
         }
+
         // -- HELPER
+
         private boolean shouldMissingXmlRootElementBeHandledOn(final Class<?> mappedType) {
             return isAllowMissingRootElement()
                     && !_Annotations.isPresent(mappedType, XmlRootElement.class); //TODO ask _ClassCache
@@ -79,6 +83,11 @@ public class JaxbUtils {
         @SneakyThrows
         private Marshaller marshaller(final JAXBContext jaxbContext, final Class<?> mappedType) {
             val marshaller = jaxbContext.createMarshaller();
+            if(properties!=null) {
+                for(val entry : properties.entrySet()) {
+                    marshaller.setProperty(entry.getKey(), entry.getValue());
+                }
+            }
             if(isFormattedOutput()) {
                 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
             }
@@ -87,6 +96,11 @@ public class JaxbUtils {
         @SneakyThrows
         private Unmarshaller unmarshaller(final JAXBContext jaxbContext, final Class<?> mappedType) {
             val unmarshaller = jaxbContext.createUnmarshaller();
+            if(properties!=null) {
+                for(val entry : properties.entrySet()) {
+                    unmarshaller.setProperty(entry.getKey(), entry.getValue());
+                }
+            }
             return unmarshaller;
         }
         @SneakyThrows