doc: document new tests and maintain Java 11 compatibility (for now) Co-authored-by-AI: IBM Bob (1.109.5+bob1.0.2)
diff --git a/src/test/java/org/eclipse/yasson/jsonstructure/Issue673.java b/src/test/java/org/eclipse/yasson/jsonstructure/Issue673.java index 7aeca3a..be2a555 100644 --- a/src/test/java/org/eclipse/yasson/jsonstructure/Issue673.java +++ b/src/test/java/org/eclipse/yasson/jsonstructure/Issue673.java
@@ -27,12 +27,35 @@ import java.util.Collections; import java.util.stream.Collectors; +/** + * Test case for Issue #673: Custom deserializers with polymorphic types and JSON structure API. + * + * <p>This test validates the interaction between: + * <ul> + * <li>Custom {@link JsonbDeserializer} implementations</li> + * <li>Polymorphic type handling via {@link JsonbTypeInfo} and {@link JsonbSubtype}</li> + * <li>JSON-P structure API ({@link JsonArray}, {@link JsonObject}, {@link JsonValue})</li> + * </ul> + * + * <p>The test ensures that custom deserializers can properly access and process JSON structure + * objects when deserializing complex types with polymorphic behavior. + * + * @see <a href="https://github.com/eclipse-ee4j/yasson/issues/673">Issue #673</a> + */ public class Issue673 { + /** + * Marker interface for objects that can be referenced. + * Implemented by both {@link Reference} and {@link IRIReference}. + */ public static interface Referenceable { } + /** + * A reference object with a description field. + * Deserialized from JSON objects containing a "description" property. + */ public static class Reference implements Referenceable { private String description; @@ -46,6 +69,10 @@ } } + /** + * An IRI (Internationalized Resource Identifier) reference. + * Deserialized from JSON string values representing URIs. + */ public static class IRIReference implements Referenceable { private String value; @@ -65,14 +92,27 @@ } } + /** + * Interface for location types with polymorphic deserialization support. + * Uses {@link JsonbTypeInfo} to determine concrete type based on "type" field in JSON. + */ @JsonbTypeInfo(key = "type", value = { - @JsonbSubtype(alias = Location.TYPE, + @JsonbSubtype(alias = Location.TYPE, type = Location.class) }) public static interface LocationInterface { } + /** + * Concrete location implementation with custom deserializers for complex fields. + * + * <p>Demonstrates: + * <ul> + * <li>Array-to-string conversion via {@link TagsDeserializer}</li> + * <li>Polymorphic reference deserialization via {@link ReferenceableDeserializer}</li> + * </ul> + */ public static class Location implements LocationInterface { public final static String TYPE = "Location"; @@ -80,6 +120,12 @@ private String tags; private Referenceable referenceable; + /** + * Gets the tags as a comma-separated string. + * Uses custom deserializer to convert JSON array to string. + * + * @return comma-separated tag string + */ @JsonbTypeDeserializer(TagsDeserializer.class) public String getTags() { return tags; @@ -89,6 +135,13 @@ this.tags = tags; } + /** + * Gets the reference object. + * Uses custom deserializer to handle polymorphic deserialization + * from either string (IRI) or object (Reference) JSON values. + * + * @return the referenceable object + */ @JsonbTypeDeserializer(ReferenceableDeserializer.class) public Referenceable getReference() { return referenceable; @@ -99,11 +152,20 @@ } } + /** + * Custom deserializer that converts a JSON array of strings into a comma-separated string. + * + * <p>Example JSON: {@code ["tag1", "tag2", "tag3"]} → {@code "tag1, tag2, tag3"} + * + * <p>This tests the ability to use {@link JsonParser#getArray()} to access + * JSON structure objects during deserialization. + */ public static class TagsDeserializer implements JsonbDeserializer<String> { @Override public String deserialize(JsonParser jp, DeserializationContext dc, Type type) { final JsonValue v = jp.getArray(); - if (v instanceof JsonArray arr) { + if (v instanceof JsonArray) { + JsonArray arr = (JsonArray) v; return arr.stream() .filter(JsonString.class::isInstance) .map(JsonString.class::cast) @@ -115,17 +177,35 @@ } + /** + * Custom deserializer that handles polymorphic deserialization of {@link Referenceable} objects. + * + * <p>Supports two JSON representations: + * <ul> + * <li>String value → {@link IRIReference} (e.g., {@code "http://example.com"})</li> + * <li>Object value → {@link Reference} (e.g., {@code {"description": "..."}})</li> + * </ul> + * + * <p>This tests the ability to: + * <ul> + * <li>Use {@link JsonParser#getValue()} to access JSON structure objects</li> + * <li>Recursively deserialize nested objects using {@link DeserializationContext#deserialize}</li> + * <li>Create new parsers from JSON-P structure objects</li> + * </ul> + */ public static class ReferenceableDeserializer implements JsonbDeserializer<Referenceable> { @Override public Referenceable deserialize(JsonParser jp, DeserializationContext dc, Type type) { final JsonValue v = jp.getValue(); - if (v instanceof JsonString str) { + if (v instanceof JsonString) { + JsonString str = (JsonString) v; return new IRIReference(str.getString()); } - if (v instanceof JsonObject obj) { + if (v instanceof JsonObject) { + JsonObject obj = (JsonObject) v; return dc.deserialize(Reference.class, - Json.createParserFactory(Collections.EMPTY_MAP) + Json.createParserFactory(Collections.emptyMap()) .createParser(obj)); } return null;
diff --git a/src/test/java/org/eclipse/yasson/jsonstructure/JsonStructureToParserAdapterTest.java b/src/test/java/org/eclipse/yasson/jsonstructure/JsonStructureToParserAdapterTest.java index d76984e..f148600 100644 --- a/src/test/java/org/eclipse/yasson/jsonstructure/JsonStructureToParserAdapterTest.java +++ b/src/test/java/org/eclipse/yasson/jsonstructure/JsonStructureToParserAdapterTest.java
@@ -285,7 +285,7 @@ Jsonb jsonb = JsonbBuilder.create(); Issue673.LocationInterface result = jsonb.fromJson(json, Issue673.LocationInterface.class); - + assertNotNull(result); assertTrue(result instanceof Issue673.Location); Issue673.Location location = (Issue673.Location) result;