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/22 11:10:28 UTC

[isis] branch spring6 updated (17d6b7e79e -> d6421b925a)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a change to branch spring6
in repository https://gitbox.apache.org/repos/asf/isis.git


    from 17d6b7e79e Merge remote-tracking branch 'origin/master' into spring6
     add 3b820c96e3 ISIS-3316: JaxbService: encapsulates verbose exception handling with JaxbUtils
     add a494a9cc35 ISIS-3316: JaxbUtils: adds JUnit test to verify type-safe xml unmarshalling
     add 47f222c335 ISIS-3316: just comments
     new d6421b925a Merge remote-tracking branch 'origin/master' into spring6

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../causeway/applib/services/jaxb/JaxbService.java | 15 +---
 commons/src/main/java/module-info.java             |  1 +
 .../org/apache/causeway/commons/io/JaxbUtils.java  | 42 +++++++----
 .../apache/causeway/commons/io/JaxbUtilsTest.java  | 88 ++++++++++++++++++++++
 .../runtimeservices/jaxb/JaxbServiceDefault.java   | 22 +++---
 5 files changed, 128 insertions(+), 40 deletions(-)
 create mode 100644 commons/src/test/java/org/apache/causeway/commons/io/JaxbUtilsTest.java


[isis] 01/01: Merge remote-tracking branch 'origin/master' into spring6

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch spring6
in repository https://gitbox.apache.org/repos/asf/isis.git

commit d6421b925a8661516f491f4198c8865462946667
Merge: 17d6b7e79e 47f222c335
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Dec 22 12:10:22 2022 +0100

    Merge remote-tracking branch 'origin/master' into spring6

 .../causeway/applib/services/jaxb/JaxbService.java | 15 +---
 commons/src/main/java/module-info.java             |  1 +
 .../org/apache/causeway/commons/io/JaxbUtils.java  | 42 +++++++----
 .../apache/causeway/commons/io/JaxbUtilsTest.java  | 88 ++++++++++++++++++++++
 .../runtimeservices/jaxb/JaxbServiceDefault.java   | 22 +++---
 5 files changed, 128 insertions(+), 40 deletions(-)

diff --cc commons/src/main/java/module-info.java
index 9f46f0e78a,64d6499f39..f6b422e3ba
--- a/commons/src/main/java/module-info.java
+++ b/commons/src/main/java/module-info.java
@@@ -71,11 -72,12 +71,12 @@@ module org.apache.causeway.commons 
      requires transitive spring.beans;
      requires transitive spring.context;
      requires transitive spring.core;
 -    requires java.inject;
 -    requires java.annotation;
 -    requires org.eclipse.persistence.moxy;
 +    requires transitive jakarta.xml.bind;
 +    requires transitive jakarta.inject;
 +    requires jakarta.annotation;
  
      // JAXB JUnit test
 -    opens org.apache.causeway.commons.internal.resources to java.xml.bind;
 -    opens org.apache.causeway.commons.io to java.xml.bind;
 +    opens org.apache.causeway.commons.internal.resources to jakarta.xml.bind;
++    opens org.apache.causeway.commons.io to jakarta.xml.bind;
  
  }
diff --cc commons/src/test/java/org/apache/causeway/commons/io/JaxbUtilsTest.java
index 0000000000,7243412394..d441b37a68
mode 000000,100644..100644
--- a/commons/src/test/java/org/apache/causeway/commons/io/JaxbUtilsTest.java
+++ b/commons/src/test/java/org/apache/causeway/commons/io/JaxbUtilsTest.java
@@@ -1,0 -1,88 +1,88 @@@
+ /*
+  *  Licensed to the Apache Software Foundation (ASF) under one
+  *  or more contributor license agreements.  See the NOTICE file
+  *  distributed with this work for additional information
+  *  regarding copyright ownership.  The ASF licenses this file
+  *  to you under the Apache License, Version 2.0 (the
+  *  "License"); you may not use this file except in compliance
+  *  with the License.  You may obtain a copy of the License at
+  *
+  *        http://www.apache.org/licenses/LICENSE-2.0
+  *
+  *  Unless required by applicable law or agreed to in writing,
+  *  software distributed under the License is distributed on an
+  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  *  KIND, either express or implied.  See the License for the
+  *  specific language governing permissions and limitations
+  *  under the License.
+  */
+ package org.apache.causeway.commons.io;
+ 
 -import javax.xml.bind.JAXBContext;
 -import javax.xml.bind.annotation.XmlAccessType;
 -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 jakarta.xml.bind.JAXBContext;
++import jakarta.xml.bind.annotation.XmlAccessType;
++import jakarta.xml.bind.annotation.XmlAccessorType;
++import jakarta.xml.bind.annotation.XmlElement;
++import jakarta.xml.bind.annotation.XmlRootElement;
++import jakarta.xml.bind.annotation.XmlType;
+ 
+ import org.junit.jupiter.api.Test;
+ 
+ import static org.junit.jupiter.api.Assertions.assertEquals;
+ 
+ import lombok.EqualsAndHashCode;
+ import lombok.Getter;
+ import lombok.Setter;
+ import lombok.val;
+ 
+ class JaxbUtilsTest {
+ 
+     @XmlRootElement(name = "type-a")
+     @XmlType
+     @XmlAccessorType(XmlAccessType.FIELD)
+     @EqualsAndHashCode
+     static class A {
+ 
+         @XmlElement(required = false)
+         @Getter @Setter private B nested;
+     }
+ 
+     @XmlRootElement(name = "type-b")
+     @XmlType
+     @XmlAccessorType(XmlAccessType.FIELD)
+     @EqualsAndHashCode
+     static class B {
+ 
+         @XmlElement(required = false)
+         @Getter @Setter private String string;
+     }
+ 
+     /**
+      * Works for arbitrary {@link XmlRootElement#name()} combinations,
+      * except you cannot use the same {@code name="root"} say on both {@link A} and {@link B}.
+      * <p>
+      * As {@link A} contains {@link B}, the {@link JAXBContext} for {@link A} should also bind type {@link B}.
+      * We are testing whether type-safe recovery especially for type {@link A} works as desired.
+      */
+     @Test
+     void typesafeUnmarshallingFromAmbiguousContext() {
+ 
+         // given
+         val b = new B();
+         b.setString("b-string");
+         val a = new A();
+         a.setNested(b);
+ 
+         // when ... doing a round trip
+         val aXml = JaxbUtils.toStringUtf8(a);
+         val bXml = JaxbUtils.toStringUtf8(b);
+ 
+         val aRecovered = JaxbUtils.tryRead(A.class, aXml).ifFailureFail().ifAbsentFail().getValue().get();
+         val bRecovered = JaxbUtils.tryRead(B.class, bXml).ifFailureFail().ifAbsentFail().getValue().get();
+ 
+         // then
+         assertEquals(a, aRecovered);
+         assertEquals(b, bRecovered);
+ 
+     }
+ 
+ }