You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2025/03/10 07:02:16 UTC
(causeway) branch main updated: CAUSEWAY-3859: regression with JAXB unable to unmarshall record ValueDecomposition
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/main by this push:
new edf015325ee CAUSEWAY-3859: regression with JAXB unable to unmarshall record ValueDecomposition
edf015325ee is described below
commit edf015325ee81a0622bf658edce808c2896a3df3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Mar 10 08:02:11 2025 +0100
CAUSEWAY-3859: regression with JAXB unable to unmarshall record
ValueDecomposition
---
.../applib/value/semantics/ValueDecomposition.java | 19 ++++++----
.../apache/causeway/commons/io/JaxbUtilsTest.java | 43 ++++++++++------------
2 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueDecomposition.java b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueDecomposition.java
index f818738e9f7..3e5244783c8 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueDecomposition.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/ValueDecomposition.java
@@ -34,7 +34,7 @@
@Programmatic
public record ValueDecomposition(
- @Nullable ValueWithTypeDto fundamental,
+ @Nullable ValueWithTypeDto fundamental,
@Nullable TypedTupleDto composite)
implements Serializable {
@@ -52,22 +52,27 @@ public static ValueDecomposition fromJson(final ValueType vType, final String js
? ofComposite(CommonDtoUtils.getCompositeValueFromJson(json))
: ofFundamental(CommonDtoUtils.getFundamentalValueFromJson(vType, json));
}
-
+
// for transport over REST
public static ValueDecomposition destringify(final ValueType vType, final String string) {
return fromJson(vType, _Strings.base64UrlDecodeZlibCompressed(string));
}
-
+
+ // as of time of writing there is no JAXB support for record types
+ ValueDecomposition() {
+ this(null, null);
+ }
+
public Optional<ValueWithTypeDto> fundamentalAsOptional() {
return Optional.ofNullable(fundamental);
}
public Optional<TypedTupleDto> compositeAsOptional() {
return Optional.ofNullable(composite);
}
-
+
// used by RO-Viewer to render values
public String toJson() {
- return fundamental!=null
+ return fundamental!=null
? CommonDtoUtils.getFundamentalValueAsJson(fundamental)
: CommonDtoUtils.getCompositeValueAsJson(composite);
}
@@ -76,7 +81,7 @@ public String toJson() {
public String stringify() {
return _Strings.base64UrlEncodeZlibCompressed(toJson());
}
-
+
public void accept(
final @NonNull Consumer<ValueWithTypeDto> fundamentalConsumer,
final @NonNull Consumer<TypedTupleDto> compositeConsumer) {
@@ -88,7 +93,7 @@ public void accept(
}
// -- DEPRECATIONS
-
+
/** @deprecated use {@link #fundamental()} instead */
@Deprecated public @Nullable ValueWithTypeDto leftIfAny() { return fundamental(); }
/** @deprecated use {@link #composite()} instead */
diff --git a/commons/src/test/java/org/apache/causeway/commons/io/JaxbUtilsTest.java b/commons/src/test/java/org/apache/causeway/commons/io/JaxbUtilsTest.java
index a6e942eb76d..de6543bc51f 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
@@ -29,7 +29,6 @@
import org.approvaltests.Approvals;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -76,34 +75,30 @@ void setup() {
a.setNested(b);
}
- @Nested
- class tryRead {
- /**
- * 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() {
-
- // when ... doing a round trip
- var aXml = JaxbUtils.toStringUtf8(a);
- var bXml = JaxbUtils.toStringUtf8(b);
+ /**
+ * 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() {
- assertTrue(_Strings.isNotEmpty(aXml));
- assertTrue(_Strings.isNotEmpty(bXml));
+ // when ... doing a round trip
+ var aXml = JaxbUtils.toStringUtf8(a);
+ var bXml = JaxbUtils.toStringUtf8(b);
- var aRecovered = JaxbUtils.tryRead(A.class, aXml).valueAsNonNullElseFail();
- var bRecovered = JaxbUtils.tryRead(B.class, bXml).valueAsNonNullElseFail();
+ assertTrue(_Strings.isNotEmpty(aXml));
+ assertTrue(_Strings.isNotEmpty(bXml));
- // then
- assertEquals(a, aRecovered);
- assertEquals(b, bRecovered);
+ var aRecovered = JaxbUtils.tryRead(A.class, aXml).valueAsNonNullElseFail();
+ var bRecovered = JaxbUtils.tryRead(B.class, bXml).valueAsNonNullElseFail();
- }
+ // then
+ assertEquals(a, aRecovered);
+ assertEquals(b, bRecovered);
}
@Test