From f3cbb35d6cd805aa01e2e701d7839533e6124fec Mon Sep 17 00:00:00 2001 From: Leonid Date: Fri, 31 Mar 2023 11:40:36 +0300 Subject: [PATCH 01/12] Fixed #589 (by adding skipObject() and skipArray() methods) (#590) Fix issue #589 (implement skipObject() and skipArray() methods) --- .../deserializer/ObjectDeserializer.java | 2 +- .../JsonStructureToParserAdapter.java | 39 +++++- .../internal/model/JsonbAnnotatedElement.java | 4 +- .../polymorphism/NestedPolymorphismTest.java | 123 ++++++++++++++++++ .../serializer/ObjectDeserializerTest.java | 8 +- 5 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 src/test/java/org/eclipse/yasson/customization/polymorphism/NestedPolymorphismTest.java diff --git a/src/main/java/org/eclipse/yasson/internal/deserializer/ObjectDeserializer.java b/src/main/java/org/eclipse/yasson/internal/deserializer/ObjectDeserializer.java index acd62edc2..fa7d914ac 100644 --- a/src/main/java/org/eclipse/yasson/internal/deserializer/ObjectDeserializer.java +++ b/src/main/java/org/eclipse/yasson/internal/deserializer/ObjectDeserializer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/org/eclipse/yasson/internal/jsonstructure/JsonStructureToParserAdapter.java b/src/main/java/org/eclipse/yasson/internal/jsonstructure/JsonStructureToParserAdapter.java index 94d378215..dfa9d64f4 100644 --- a/src/main/java/org/eclipse/yasson/internal/jsonstructure/JsonStructureToParserAdapter.java +++ b/src/main/java/org/eclipse/yasson/internal/jsonstructure/JsonStructureToParserAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -25,6 +25,9 @@ import jakarta.json.stream.JsonLocation; import jakarta.json.stream.JsonParser; +import org.eclipse.yasson.internal.properties.MessageKeys; +import org.eclipse.yasson.internal.properties.Messages; + /** * Adapter for {@link JsonParser}, that reads a {@link JsonStructure} content tree instead of JSON text. * @@ -66,9 +69,9 @@ public Event next() { JsonStructureIterator current = iterators.peek(); Event next = current.next(); if (next == Event.START_OBJECT) { - iterators.push(new JsonObjectIterator((JsonObject) iterators.peek().getValue())); + iterators.push(new JsonObjectIterator((JsonObject) current.getValue())); } else if (next == Event.START_ARRAY) { - iterators.push(new JsonArrayIterator((JsonArray) iterators.peek().getValue())); + iterators.push(new JsonArrayIterator((JsonArray) current.getValue())); } else if (next == Event.END_OBJECT || next == Event.END_ARRAY) { iterators.pop(); } @@ -102,8 +105,14 @@ public BigDecimal getBigDecimal() { @Override public JsonObject getObject() { -// ((JsonObjectIterator) iterators.peek()).jsonObject - return iterators.peek().getValue().asJsonObject(); + JsonStructureIterator current = iterators.peek(); + if (current instanceof JsonObjectIterator) { + //Remove child iterator as getObject() method contract says + iterators.pop(); + return current.getValue().asJsonObject(); + } else { + throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Outside of object context")); + } } private JsonNumber getJsonNumberValue() { @@ -120,6 +129,26 @@ public JsonLocation getLocation() { throw new JsonbException("Operation not supported"); } + @Override + public void skipArray() { + if (!iterators.isEmpty()) { + JsonStructureIterator current = iterators.peek(); + if (current instanceof JsonArrayIterator) { + iterators.pop(); + } + } + } + + @Override + public void skipObject() { + if (!iterators.isEmpty()) { + JsonStructureIterator current = iterators.peek(); + if (current instanceof JsonObjectIterator) { + iterators.pop(); + } + } + } + @Override public void close() { //noop diff --git a/src/main/java/org/eclipse/yasson/internal/model/JsonbAnnotatedElement.java b/src/main/java/org/eclipse/yasson/internal/model/JsonbAnnotatedElement.java index 774be03b2..b93abe986 100644 --- a/src/main/java/org/eclipse/yasson/internal/model/JsonbAnnotatedElement.java +++ b/src/main/java/org/eclipse/yasson/internal/model/JsonbAnnotatedElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -100,7 +100,7 @@ public void putAnnotation(Annotation annotation, boolean inherited, Class def // } // annotations.put(annotation.annotationType(), new AnnotationWrapper(annotation, inherited)); annotations.computeIfAbsent(annotation.annotationType(), aClass -> new LinkedList<>()) - .add(new AnnotationWrapper(annotation, inherited, definedType)); + .add(new AnnotationWrapper(annotation, inherited, definedType)); } public void putAnnotationWrapper(AnnotationWrapper annotationWrapper) { diff --git a/src/test/java/org/eclipse/yasson/customization/polymorphism/NestedPolymorphismTest.java b/src/test/java/org/eclipse/yasson/customization/polymorphism/NestedPolymorphismTest.java new file mode 100644 index 000000000..fe1c4dd1c --- /dev/null +++ b/src/test/java/org/eclipse/yasson/customization/polymorphism/NestedPolymorphismTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +package org.eclipse.yasson.customization.polymorphism; + +import jakarta.json.bind.annotation.JsonbSubtype; +import jakarta.json.bind.annotation.JsonbTypeInfo; + +import org.eclipse.yasson.Jsonbs; +import org.junit.jupiter.api.Test; + +import static org.eclipse.yasson.Jsonbs.defaultJsonb; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Tests for verification of proper polymorphism handling based on annotation. + */ +public class NestedPolymorphismTest { + + /** + * 1st test for: https://github.com/eclipse-ee4j/yasson/issues/589 + *

(deserialization of nested polymorphic and unmapped properties) + */ + @Test + public void testNestedUnmappedProperty() { + String json = "{\"inner\":{\"id\":123,\"@type\":\"derivationA\"," + + "\"unmapped\":{\"x\":9,\"y\":[9,8,7]},\"name\":\"abc\"}}"; + Outer obj = assertDoesNotThrow(() -> defaultJsonb.fromJson(json, Outer.class)); + assertEquals(123L, obj.inner.id); + assertEquals("abc", obj.inner.name); + } + + // a base class + @JsonbTypeInfo(key = "@type", value = + @JsonbSubtype(type = InnerBase.class, alias = "derivationA")) + public static class InnerBase { + public Long id; + public String name; + } + + // derivation of the base class + public class Derivation extends InnerBase {} + + // an arbitrary 'outer' root element + public static class Outer { + public InnerBase inner; + } + + /** + * 2nd test for: https://github.com/eclipse-ee4j/yasson/issues/589 + *

(deserialization of multiple nested polymorphic properties) + */ + @Test + public void testNestedDeserialization() { + String json = "{\"@type\":\"Pets\",\"pet1\":{\"@type\":\"Cat\",\"name\":\"kitty\"}" + + ",\"pet2\":{\"@type\":\"Dog\",\"name\":\"puppy\"}}"; + final Animals animals = Jsonbs.defaultJsonb.fromJson(json, Animals.class); + assertThat(animals, instanceOf(Pets.class)); + assertNotNull(((Pets) animals).pet1, "Empty 'pet1' property"); + assertEquals("kitty", ((Cat) ((Pets) animals).pet1).name, "First pet has invalid name"); + assertNotNull(((Pets) animals).pet2, "Empty 'pet2' property"); + assertThat("Invalid pet nr 2", ((Pets) animals).pet2, instanceOf(Dog.class)); + } + + @JsonbTypeInfo(key = "@type", value = { + @JsonbSubtype(alias = "Dog", type = Dog.class), + @JsonbSubtype(alias = "Cat", type = Cat.class) + }) + public interface Pet { + public String getType(); + } + + public static class Dog implements Pet { + + public String name; + + @Override + public String getType() { + return "Dog"; + } + } + + public static class Cat implements Pet { + + public String name; + + @Override + public String getType() { + return "Cat"; + } + } + + @JsonbTypeInfo(key = "@type", value = { + @JsonbSubtype(alias = "Pets", type = Pets.class), + @JsonbSubtype(alias = "Fishes", type = Fishes.class) + }) + public interface Animals { + + } + + public static class Pets implements Animals { + public Pet pet1; + public Pet pet2; + } + + public static class Fishes implements Animals { + + } + +} diff --git a/src/test/java/org/eclipse/yasson/internal/serializer/ObjectDeserializerTest.java b/src/test/java/org/eclipse/yasson/internal/serializer/ObjectDeserializerTest.java index ad2f0d04b..3c4158159 100644 --- a/src/test/java/org/eclipse/yasson/internal/serializer/ObjectDeserializerTest.java +++ b/src/test/java/org/eclipse/yasson/internal/serializer/ObjectDeserializerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -22,9 +22,9 @@ public class ObjectDeserializerTest { @Test public void testGetInstanceExceptionShouldContainClassNameOnMissingConstructor() { - assertThrows(JsonbException.class, - () -> defaultJsonb.fromJson("{\"key\":\"value\"}", DummyDeserializationClass.class), - DummyDeserializationClass.class::getName); + assertThrows(JsonbException.class, + () -> defaultJsonb.fromJson("{\"key\":\"value\"}", DummyDeserializationClass.class), + DummyDeserializationClass.class::getName); } public static class DummyDeserializationClass { From 16badeec0b92a51022e271b024deaede7a170b35 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Mon, 26 Dec 2022 20:18:10 +0100 Subject: [PATCH 02/12] Close Parsers and Generators Close parsers and generators to return buffers to the pool. --- .../eclipse/yasson/internal/JsonBinding.java | 72 ++++++++++++------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/eclipse/yasson/internal/JsonBinding.java b/src/main/java/org/eclipse/yasson/internal/JsonBinding.java index c15b7ebbf..cd4764a3a 100644 --- a/src/main/java/org/eclipse/yasson/internal/JsonBinding.java +++ b/src/main/java/org/eclipse/yasson/internal/JsonBinding.java @@ -57,54 +57,64 @@ private T deserialize(final Type type, final JsonParser parser, final Deseri @Override public T fromJson(String str, Class type) throws JsonbException { - final JsonParser parser = jsonbContext.getJsonProvider().createParser(new StringReader(str)); - final DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); - return deserialize(type, parser, unmarshaller); + try (JsonParser parser = jsonbContext.getJsonProvider().createParser(new StringReader(str))) { + final DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); + return deserialize(type, parser, unmarshaller); + } } @Override public T fromJson(String str, Type type) throws JsonbException { - JsonParser parser = jsonbContext.getJsonProvider().createParser(new StringReader(str)); - DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); - return deserialize(type, parser, unmarshaller); + try (JsonParser parser = jsonbContext.getJsonProvider().createParser(new StringReader(str))) { + DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); + return deserialize(type, parser, unmarshaller); + } } @Override public T fromJson(Reader reader, Class type) throws JsonbException { - JsonParser parser = jsonbContext.getJsonProvider().createParser(reader); - DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); - return deserialize(type, parser, unmarshaller); + try (JsonParser parser = jsonbContext.getJsonProvider().createParser(reader)) { + DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); + return deserialize(type, parser, unmarshaller); + } } @Override public T fromJson(Reader reader, Type type) throws JsonbException { - JsonParser parser = jsonbContext.getJsonProvider().createParser(reader); - DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); - return deserialize(type, parser, unmarshaller); + try (JsonParser parser = jsonbContext.getJsonProvider().createParser(reader)) { + DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); + return deserialize(type, parser, unmarshaller); + } } @Override public T fromJson(InputStream stream, Class clazz) throws JsonbException { DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); - return deserialize(clazz, inputStreamParser(stream), unmarshaller); + try (JsonParser parser = inputStreamParser(stream)) { + return deserialize(clazz, inputStreamParser(stream), unmarshaller); + } } @Override public T fromJson(InputStream stream, Type type) throws JsonbException { DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); - return deserialize(type, inputStreamParser(stream), unmarshaller); + try (JsonParser parser = inputStreamParser(stream)) { + return deserialize(type, inputStreamParser(stream), unmarshaller); + } } @Override public T fromJsonStructure(JsonStructure jsonStructure, Class type) throws JsonbException { - JsonParser parser = new JsonStructureToParserAdapter(jsonStructure); - return deserialize(type, parser, new DeserializationContextImpl(jsonbContext)); + try (JsonParser parser = new JsonStructureToParserAdapter(jsonStructure)) { + return deserialize(type, parser, new DeserializationContextImpl(jsonbContext)); + } } @Override public T fromJsonStructure(JsonStructure jsonStructure, Type runtimeType) throws JsonbException { - JsonParser parser = new JsonStructureToParserAdapter(jsonStructure); - return deserialize(runtimeType, parser, new DeserializationContextImpl(jsonbContext)); + try (JsonParser parser = new JsonStructureToParserAdapter(jsonStructure)) { + return deserialize(runtimeType, parser, new DeserializationContextImpl(jsonbContext)); + } } private JsonParser inputStreamParser(InputStream stream) { @@ -117,29 +127,35 @@ private JsonParser inputStreamParser(InputStream stream) { @Override public String toJson(Object object) throws JsonbException { StringWriter writer = new StringWriter(); - final JsonGenerator generator = writerGenerator(writer); - new SerializationContextImpl(jsonbContext).marshall(object, generator); + try (JsonGenerator generator = writerGenerator(writer)) { + new SerializationContextImpl(jsonbContext).marshall(object, generator); + } return writer.toString(); } @Override public String toJson(Object object, Type type) throws JsonbException { StringWriter writer = new StringWriter(); - final JsonGenerator generator = writerGenerator(writer); - new SerializationContextImpl(jsonbContext, type).marshall(object, generator); + try (JsonGenerator generator = writerGenerator(writer)) { + new SerializationContextImpl(jsonbContext, type).marshall(object, generator); + } return writer.toString(); } @Override public void toJson(Object object, Writer writer) throws JsonbException { final SerializationContextImpl marshaller = new SerializationContextImpl(jsonbContext); - marshaller.marshallWithoutClose(object, writerGenerator(writer)); + try (JsonGenerator generator = writerGenerator(writer)) { + marshaller.marshallWithoutClose(object, generator); + } } @Override public void toJson(Object object, Type type, Writer writer) throws JsonbException { final SerializationContextImpl marshaller = new SerializationContextImpl(jsonbContext, type); - marshaller.marshallWithoutClose(object, writerGenerator(writer)); + try (JsonGenerator generator = writerGenerator(writer)) { + marshaller.marshallWithoutClose(object, generator); + } } private JsonGenerator writerGenerator(Writer writer) { @@ -153,13 +169,17 @@ private JsonGenerator writerGenerator(Writer writer) { @Override public void toJson(Object object, OutputStream stream) throws JsonbException { final SerializationContextImpl marshaller = new SerializationContextImpl(jsonbContext); - marshaller.marshall(object, streamGenerator(stream)); + try (JsonGenerator generator = streamGenerator(stream)) { + marshaller.marshall(object, generator); + } } @Override public void toJson(Object object, Type type, OutputStream stream) throws JsonbException { final SerializationContextImpl marshaller = new SerializationContextImpl(jsonbContext, type); - marshaller.marshall(object, streamGenerator(stream)); + try (JsonGenerator generator = streamGenerator(stream)) { + marshaller.marshall(object, generator); + } } @Override From 6ad7385824e85e97321a6fcd903d26f497578b17 Mon Sep 17 00:00:00 2001 From: Eclipse Yasson Bot Date: Mon, 3 Apr 2023 07:42:55 +0000 Subject: [PATCH 03/12] Prepare release org.eclipse:yasson:3.0.3-RELEASE --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c554ef36d..1589531d5 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 4.0.0 org.eclipse yasson - 3.0.3-SNAPSHOT + 3.0.3 jar Yasson From 6e5b0b1580fd8aac63c73ca6701b004e576f3ee9 Mon Sep 17 00:00:00 2001 From: Eclipse Yasson Bot Date: Mon, 3 Apr 2023 07:44:22 +0000 Subject: [PATCH 04/12] Prepare next development cycle for 3.0.4-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1589531d5..d7f4e6a72 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 4.0.0 org.eclipse yasson - 3.0.3 + 3.0.4-SNAPSHOT jar Yasson From f371eb5b2907b35ab9db0980ded6f17c7b7ccceb Mon Sep 17 00:00:00 2001 From: amoscatelli Date: Thu, 24 Aug 2023 12:19:57 +0200 Subject: [PATCH 05/12] Support retrieving lower bound from TypeVariable in Collection attribute (#580) Support retrieving lower bound from TypeVariable in Collection attribute --- .../yasson/internal/ReflectionUtils.java | 8 +++++ .../defaultmapping/generics/GenericsTest.java | 29 +++++++++++++++++ ...eVariableWithCollectionAttributeClass.java | 32 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/test/java/org/eclipse/yasson/defaultmapping/generics/model/LowerBoundTypeVariableWithCollectionAttributeClass.java diff --git a/src/main/java/org/eclipse/yasson/internal/ReflectionUtils.java b/src/main/java/org/eclipse/yasson/internal/ReflectionUtils.java index 724783972..a5eac94cf 100644 --- a/src/main/java/org/eclipse/yasson/internal/ReflectionUtils.java +++ b/src/main/java/org/eclipse/yasson/internal/ReflectionUtils.java @@ -240,6 +240,14 @@ public static Type resolveTypeArguments(ParameterizedType typeToResolve, Type ty } resolvedArgs[i] = new VariableTypeInheritanceSearch() .searchParametrizedType(typeToSearch, (TypeVariable) variableType); + + if (resolvedArgs[i] == null) { + Type[] bounds = ((TypeVariable) variableType).getBounds(); + if (Objects.nonNull(bounds) && bounds.length > 0) { + resolvedArgs[i] = bounds[0]; + } + } + if (resolvedArgs[i] == null) { if (typeToSearch instanceof Class) { return Object.class; diff --git a/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java b/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java index 3bc88a049..b193521ca 100644 --- a/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java +++ b/src/test/java/org/eclipse/yasson/defaultmapping/generics/GenericsTest.java @@ -29,6 +29,8 @@ import jakarta.json.bind.Jsonb; import jakarta.json.bind.JsonbBuilder; import jakarta.json.bind.JsonbConfig; +import java.lang.reflect.Field; +import java.util.Collection; import org.eclipse.yasson.TestTypeToken; import org.eclipse.yasson.adapters.model.GenericBox; import org.eclipse.yasson.defaultmapping.generics.model.AnotherGenericTestClass; @@ -54,6 +56,7 @@ import org.junit.jupiter.api.Test; import static org.eclipse.yasson.Jsonbs.defaultJsonb; +import org.eclipse.yasson.defaultmapping.generics.model.LowerBoundTypeVariableWithCollectionAttributeClass; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -446,6 +449,32 @@ public void multipleGenericLevels() { assertEquals(concreteContainer, finalGenericWrapper); } + @Test + public void lowerBoundTypeVariableInCollectionAttribute() throws Exception { + + Shape shape = new Shape(); + shape.setArea(5D); + + AnotherGenericTestClass anotherGenericTestClass = new AnotherGenericTestClass<>(); + anotherGenericTestClass.field1 = 6; + anotherGenericTestClass.field2 = shape; + + List> asList = Arrays.asList(anotherGenericTestClass); + + Jsonb jsonb = JsonbBuilder.create(); + String toJson = jsonb.toJson(asList); + + Field field = LowerBoundTypeVariableWithCollectionAttributeClass.class.getDeclaredField("value"); + + Type genericType = field.getGenericType(); + + List> fromJson = jsonb.fromJson(toJson, genericType); + + assertEquals(5, fromJson.get(0).field2.getArea()); + assertEquals(6, fromJson.get(0).field1); + + } + public interface FunctionalInterface { T getValue(); } diff --git a/src/test/java/org/eclipse/yasson/defaultmapping/generics/model/LowerBoundTypeVariableWithCollectionAttributeClass.java b/src/test/java/org/eclipse/yasson/defaultmapping/generics/model/LowerBoundTypeVariableWithCollectionAttributeClass.java new file mode 100644 index 000000000..3b7198a6e --- /dev/null +++ b/src/test/java/org/eclipse/yasson/defaultmapping/generics/model/LowerBoundTypeVariableWithCollectionAttributeClass.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +package org.eclipse.yasson.defaultmapping.generics.model; + +import java.util.Collection; + +/** + * @author Alessandro Moscatelli + */ +public class LowerBoundTypeVariableWithCollectionAttributeClass { + + private Collection> value; + + public Collection> getValue() { + return value; + } + + public void setValue(Collection> value) { + this.value = value; + } + +} From cef363667d21cbd6d6c17170e9bdc57b9f3d059d Mon Sep 17 00:00:00 2001 From: David Kral Date: Thu, 12 Oct 2023 17:35:51 +0200 Subject: [PATCH 06/12] copyright update Signed-off-by: David Kral --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d7f4e6a72..0abc66b76 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ - + diff --git a/pom.xml b/pom.xml index 0abc66b76..b17b70c8a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ + 2.2 + 3.0.0 + 6.0.0 + 4.1.0 + 2.2.0 + 3.0.1 + 2.1.3 + 1.1.6 + 5.10.2 + 6.0.0.Beta1 + + + 3.6.0 + 3.2.0 + 4.8.5.0 + 2.4 + 5.1.9 + 3.3.1 + 3.13.0 + 3.4.1 + 3.4.1 + 3.6.3 + 3.2.5 @@ -51,17 +73,17 @@ jakarta.el jakarta.el-api - 5.0.0 + ${jakarta.el-api.version} jakarta.interceptor jakarta.interceptor-api - 2.1.0 + ${jakarta.interceptor-api.version} jakarta.annotation jakarta.annotation-api - 2.1.0 + ${jakarta.annotation-api.version} @@ -81,7 +103,7 @@ org.eclipse.parsson parsson - 1.1.0 + ${jakarta.parson.version} @@ -93,25 +115,25 @@ org.jboss.weld.se weld-se-core - 5.0.0.Final + ${weld-se-core.version} test org.junit.jupiter junit-jupiter-api - 5.8.2 + ${junit-jupiter.version} test org.junit.jupiter junit-jupiter-engine - 5.8.2 + ${junit-jupiter.version} test org.hamcrest hamcrest - 2.2 + ${hamcrest.version} test @@ -223,29 +245,23 @@ - copyright + spotbugs - org.glassfish.copyright - glassfish-copyright-maven-plugin + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + + Low + - - print-copyright - - copyright - - validate - - - - check-copyright + analyze-compile + compile check - validate @@ -253,159 +269,48 @@ - jdk16 - - [16,) - + copyright - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 + org.glassfish.copyright + glassfish-copyright-maven-plugin + - default-testCompile - - 16 - - ${project.basedir}/src/test/java - ${project.basedir}/src/test/java16 - - + print-copyright + + copyright + + validate - - - - org.apache.maven.plugins - maven-failsafe-plugin - + + check-copyright - integration-test - verify + check + validate - - - **/RecordTest.java - - - - - - staging - - false - - - - sonatype-nexus-staging - Sonatype Nexus Staging - ${sonatypeOssDistMgmtStagingUrl} - - true - - - true - - - - - - sonatype-nexus-staging - Sonatype Nexus Staging - ${sonatypeOssDistMgmtStagingUrl} - - true - - - true - - - - - - - - - - ${project.artifactId} - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - Max - Low - true - - - - analyze-compile - compile - - check - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.0.0-M3 - org.apache.maven.plugins maven-compiler-plugin - 3.8.1 - - - default-compile - - compile - - - 11 - 11 - 11 - - - - default-testCompile - - 11 - - - - multi-release-compile-16 - - compile - - - 16 - - ${project.basedir}/src/main/java16 - - true - - - + ${maven-compiler-plugin.version} - -proc:none -Xlint:all @@ -413,13 +318,10 @@ org.apache.maven.plugins maven-jar-plugin - 3.0.2 + ${maven-jar-plugin.version} ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - true - @@ -427,7 +329,7 @@ org.codehaus.mojo buildnumber-maven-plugin - 1.4 + ${buildnumber-maven-plugin.version} {0,date,MM/dd/yyyy hh:mm aa} @@ -446,42 +348,15 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + ${maven-javadoc-plugin.version} - Yasson - ${basedir}/src/main/java/org/eclipse/yasson - - --add-modules - jakarta.json.bind,jakarta.json - - 11 + ]]> - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar-no-fork - - - org.apache.felix maven-bundle-plugin - 5.1.1 + ${maven-bundle-plugin.version} osgi-bundle @@ -514,7 +389,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M3 + ${maven-surefire-plugin.version} default-test @@ -549,7 +424,7 @@ - --limit-modules java.base,java.logging,java.sql,jakarta.json.bind,jakarta.json,java.management,jdk.localedata + --limit-modules java.base,java.logging,java.sql,jakarta.json.bind,jakarta.json,java.management,jdk.localedata,org.eclipse.parsson,org.eclipse.yasson **/JavaxNamingExcludedTest.class @@ -562,7 +437,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.0.0-M2 + ${maven-enforcer-plugin.version} enforce-versions @@ -574,10 +449,10 @@ - [11,) + [17,) - [3.3.9,) + [3.6.0,) @@ -586,7 +461,7 @@ org.codehaus.mojo build-helper-maven-plugin - 3.0.0 + ${build-helper-maven-plugin.version} add-resource @@ -612,33 +487,19 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.0 + ${maven-checkstyle-plugin.version} etc/checkstyle.xml etc/checkstyle-suppressions.xml - UTF-8 true true false - - - com.puppycrawl.tools - checkstyle - 8.29 - - - com.sun - tools - - - - org.glassfish.copyright glassfish-copyright-maven-plugin - 2.3 + ${glassfish-copyright-maven-plugin.version} etc/copyright.txt etc/copyright-exclude.txt @@ -691,14 +552,4 @@ - - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index f6c0ace2b..12366c5db 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -11,7 +11,7 @@ */ /** - * Eclipse implementation of the JSONB-API. + * Yasson, the implementation of the Jakarta JSON Binding. */ module org.eclipse.yasson { requires jakarta.json; diff --git a/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java b/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java index bcf0b14c6..2f3d2dc44 100644 --- a/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java +++ b/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -22,6 +22,8 @@ import org.eclipse.yasson.internal.model.JsonbCreator; import org.eclipse.yasson.internal.model.Property; +import org.eclipse.yasson.internal.properties.MessageKeys; +import org.eclipse.yasson.internal.properties.Messages; /** * Search for instance creator from other sources. @@ -34,25 +36,38 @@ private ClassMultiReleaseExtension() { } static boolean shouldTransformToPropertyName(Method method) { - return true; + return !method.getDeclaringClass().isRecord(); } static boolean isSpecialAccessorMethod(Method method, Map classProperties) { - return false; + return isRecord(method.getDeclaringClass()) + && method.getParameterCount() == 0 + && !void.class.equals(method.getReturnType()) + && classProperties.containsKey(method.getName()); } static JsonbCreator findCreator(Class clazz, Constructor[] declaredConstructors, AnnotationIntrospector introspector, PropertyNamingStrategy propertyNamingStrategy) { + if (clazz.isRecord()) { + if (declaredConstructors.length == 1) { + return introspector.createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy); + } + } return null; } public static boolean isRecord(Class clazz) { - return false; + return clazz.isRecord(); } public static Optional exceptionToThrow(Class clazz) { + if (clazz.isRecord()) { + if (clazz.getDeclaredConstructors().length > 1) { + return Optional.of(new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz))); + } + } return Optional.empty(); } diff --git a/src/main/java/org/eclipse/yasson/internal/JsonBinding.java b/src/main/java/org/eclipse/yasson/internal/JsonBinding.java index cd4764a3a..fb185deb0 100644 --- a/src/main/java/org/eclipse/yasson/internal/JsonBinding.java +++ b/src/main/java/org/eclipse/yasson/internal/JsonBinding.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -91,7 +91,7 @@ public T fromJson(Reader reader, Type type) throws JsonbException { public T fromJson(InputStream stream, Class clazz) throws JsonbException { DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); try (JsonParser parser = inputStreamParser(stream)) { - return deserialize(clazz, inputStreamParser(stream), unmarshaller); + return deserialize(clazz, parser, unmarshaller); } } @@ -99,7 +99,7 @@ public T fromJson(InputStream stream, Class clazz) throws JsonbException public T fromJson(InputStream stream, Type type) throws JsonbException { DeserializationContextImpl unmarshaller = new DeserializationContextImpl(jsonbContext); try (JsonParser parser = inputStreamParser(stream)) { - return deserialize(type, inputStreamParser(stream), unmarshaller); + return deserialize(type, parser, unmarshaller); } } diff --git a/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java b/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java deleted file mode 100644 index 2b062bf06..000000000 --- a/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0, - * or the Eclipse Distribution License v. 1.0 which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - */ - -package org.eclipse.yasson.internal; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Optional; - -import jakarta.json.bind.JsonbException; -import jakarta.json.bind.config.PropertyNamingStrategy; - -import org.eclipse.yasson.internal.model.JsonbCreator; -import org.eclipse.yasson.internal.model.Property; -import org.eclipse.yasson.internal.properties.MessageKeys; -import org.eclipse.yasson.internal.properties.Messages; - -/** - * Search for instance creator from other sources. - * Mainly intended to add extensibility for different java versions and new features. - */ -public class ClassMultiReleaseExtension { - - private ClassMultiReleaseExtension() { - throw new IllegalStateException("This class cannot be instantiated"); - } - - static boolean shouldTransformToPropertyName(Method method) { - return !method.getDeclaringClass().isRecord(); - } - - static boolean isSpecialAccessorMethod(Method method, Map classProperties) { - return isRecord(method.getDeclaringClass()) - && method.getParameterCount() == 0 - && !void.class.equals(method.getReturnType()) - && classProperties.containsKey(method.getName()); - } - - static JsonbCreator findCreator(Class clazz, - Constructor[] declaredConstructors, - AnnotationIntrospector introspector, - PropertyNamingStrategy propertyNamingStrategy) { - if (clazz.isRecord()) { - if (declaredConstructors.length == 1) { - return introspector.createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy); - } - } - return null; - } - - public static boolean isRecord(Class clazz) { - return clazz.isRecord(); - } - - public static Optional exceptionToThrow(Class clazz) { - if (clazz.isRecord()) { - if (clazz.getDeclaredConstructors().length > 1) { - return Optional.of(new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz))); - } - } - return Optional.empty(); - } - -} diff --git a/src/test/java/org/eclipse/yasson/defaultmapping/SecurityManagerTest.java b/src/test/java/org/eclipse/yasson/defaultmapping/SecurityManagerTest.java deleted file mode 100644 index 029e55402..000000000 --- a/src/test/java/org/eclipse/yasson/defaultmapping/SecurityManagerTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0, - * or the Eclipse Distribution License v. 1.0 which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - */ - -package org.eclipse.yasson.defaultmapping; - -import org.junit.jupiter.api.*; - -import org.eclipse.yasson.serializers.model.Crate; - -import jakarta.json.bind.Jsonb; -import jakarta.json.bind.JsonbBuilder; -import jakarta.json.bind.JsonbConfig; -import jakarta.json.bind.annotation.JsonbProperty; -import jakarta.json.bind.config.PropertyVisibilityStrategy; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.math.BigDecimal; - -/** - * Created by Roman Grigoriadi (roman.grigoriadi@oracle.com) on 28/04/2017. - */ - -public class SecurityManagerTest { - - static final String classesDir = SecurityManagerTest.class.getProtectionDomain().getCodeSource().getLocation().getFile(); - - @BeforeAll - public static void setUp() { - System.setProperty("java.security.policy", classesDir + "test.policy"); - System.setProperty("java.security.debug", "failure"); - System.setSecurityManager(new SecurityManager()); - } - - @AfterAll - public static void tearDown() { - System.setSecurityManager(null); - } - - @Test - public void testWithSecurityManager() { - Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyVisibilityStrategy(new PropertyVisibilityStrategy() { - @Override - public boolean isVisible(Field field) { - return Modifier.isPublic(field.getModifiers()) || field.getName().equals("privateProperty"); - } - - @Override - public boolean isVisible(Method method) { - return Modifier.isPublic(method.getModifiers()); - } - })); - - Pojo pojo = new Pojo(); - pojo.setStrProperty("string propery"); - Crate crate = new Crate(); - crate.crateBigDec = BigDecimal.TEN; - crate.crateStr = "crate string"; - pojo.setCrate(crate); - - String result = jsonb.toJson(pojo); - } - - - - public static class Pojo { - - //causes .setAccessible(true) in combination with custom visibility strategy - private String privateProperty; - - @JsonbProperty("property1") - private String strProperty; - - @JsonbProperty("property2") - private Crate crate; - - public String getStrProperty() { - return strProperty; - } - - public void setStrProperty(String strProperty) { - this.strProperty = strProperty; - } - - public Crate getCrate() { - return crate; - } - - public void setCrate(Crate crate) { - this.crate = crate; - } - } -} diff --git a/src/test/java/org/eclipse/yasson/internal/cdi/JndiBeanManager.java b/src/test/java/org/eclipse/yasson/internal/cdi/JndiBeanManager.java index 86986244a..9087ef962 100644 --- a/src/test/java/org/eclipse/yasson/internal/cdi/JndiBeanManager.java +++ b/src/test/java/org/eclipse/yasson/internal/cdi/JndiBeanManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -39,6 +39,7 @@ import jakarta.enterprise.inject.spi.ProducerFactory; import java.lang.annotation.Annotation; import java.lang.reflect.Type; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -163,6 +164,11 @@ public Context getContext(Class scopeType) { throw new UnsupportedOperationException("Not implemented"); } + @Override + public Collection getContexts(Class aClass) { + throw new UnsupportedOperationException("Not implemented"); + } + @Override public ELResolver getELResolver() { throw new UnsupportedOperationException("Not implemented"); @@ -242,4 +248,14 @@ public Event getEvent() { public Instance createInstance() { throw new UnsupportedOperationException("Not implemented"); } + + @Override + public boolean isMatchingBean(Set set, Set set1, Type type, Set set2) { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public boolean isMatchingEvent(Type type, Set set, Type type1, Set set1) { + throw new UnsupportedOperationException("Not implemented"); + } } diff --git a/src/test/java16/org/eclipse/yasson/records/Car.java b/src/test/java/org/eclipse/yasson/records/Car.java similarity index 87% rename from src/test/java16/org/eclipse/yasson/records/Car.java rename to src/test/java/org/eclipse/yasson/records/Car.java index d0013156b..d32e31732 100644 --- a/src/test/java16/org/eclipse/yasson/records/Car.java +++ b/src/test/java/org/eclipse/yasson/records/Car.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/CarWithCreateNamingStrategyTest.java b/src/test/java/org/eclipse/yasson/records/CarWithCreateNamingStrategyTest.java similarity index 96% rename from src/test/java16/org/eclipse/yasson/records/CarWithCreateNamingStrategyTest.java rename to src/test/java/org/eclipse/yasson/records/CarWithCreateNamingStrategyTest.java index 57c240775..d1875be1c 100644 --- a/src/test/java16/org/eclipse/yasson/records/CarWithCreateNamingStrategyTest.java +++ b/src/test/java/org/eclipse/yasson/records/CarWithCreateNamingStrategyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/CarWithCreator.java b/src/test/java/org/eclipse/yasson/records/CarWithCreator.java similarity index 90% rename from src/test/java16/org/eclipse/yasson/records/CarWithCreator.java rename to src/test/java/org/eclipse/yasson/records/CarWithCreator.java index 08f5978b0..b19fa0bbb 100644 --- a/src/test/java16/org/eclipse/yasson/records/CarWithCreator.java +++ b/src/test/java/org/eclipse/yasson/records/CarWithCreator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/CarWithDefaultConstructor.java b/src/test/java/org/eclipse/yasson/records/CarWithDefaultConstructor.java similarity index 87% rename from src/test/java16/org/eclipse/yasson/records/CarWithDefaultConstructor.java rename to src/test/java/org/eclipse/yasson/records/CarWithDefaultConstructor.java index 3a9f3988d..c5bc54038 100644 --- a/src/test/java16/org/eclipse/yasson/records/CarWithDefaultConstructor.java +++ b/src/test/java/org/eclipse/yasson/records/CarWithDefaultConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/CarWithExtraMethod.java b/src/test/java/org/eclipse/yasson/records/CarWithExtraMethod.java similarity index 87% rename from src/test/java16/org/eclipse/yasson/records/CarWithExtraMethod.java rename to src/test/java/org/eclipse/yasson/records/CarWithExtraMethod.java index 685a23768..35cba7b57 100644 --- a/src/test/java16/org/eclipse/yasson/records/CarWithExtraMethod.java +++ b/src/test/java/org/eclipse/yasson/records/CarWithExtraMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/CarWithMultipleConstructors.java b/src/test/java/org/eclipse/yasson/records/CarWithMultipleConstructors.java similarity index 87% rename from src/test/java16/org/eclipse/yasson/records/CarWithMultipleConstructors.java rename to src/test/java/org/eclipse/yasson/records/CarWithMultipleConstructors.java index 39f6ef429..59e302d74 100644 --- a/src/test/java16/org/eclipse/yasson/records/CarWithMultipleConstructors.java +++ b/src/test/java/org/eclipse/yasson/records/CarWithMultipleConstructors.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/CarWithMultipleConstructorsAndCreator.java b/src/test/java/org/eclipse/yasson/records/CarWithMultipleConstructorsAndCreator.java similarity index 90% rename from src/test/java16/org/eclipse/yasson/records/CarWithMultipleConstructorsAndCreator.java rename to src/test/java/org/eclipse/yasson/records/CarWithMultipleConstructorsAndCreator.java index 6a0181928..c98fd21a0 100644 --- a/src/test/java16/org/eclipse/yasson/records/CarWithMultipleConstructorsAndCreator.java +++ b/src/test/java/org/eclipse/yasson/records/CarWithMultipleConstructorsAndCreator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/CarWithoutAnnotations.java b/src/test/java/org/eclipse/yasson/records/CarWithoutAnnotations.java similarity index 85% rename from src/test/java16/org/eclipse/yasson/records/CarWithoutAnnotations.java rename to src/test/java/org/eclipse/yasson/records/CarWithoutAnnotations.java index fc1511edb..b6cca66a2 100644 --- a/src/test/java16/org/eclipse/yasson/records/CarWithoutAnnotations.java +++ b/src/test/java/org/eclipse/yasson/records/CarWithoutAnnotations.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/test/java16/org/eclipse/yasson/records/RecordTest.java b/src/test/java/org/eclipse/yasson/records/RecordTest.java similarity index 98% rename from src/test/java16/org/eclipse/yasson/records/RecordTest.java rename to src/test/java/org/eclipse/yasson/records/RecordTest.java index f8ebdd19a..2b6a61ec8 100644 --- a/src/test/java16/org/eclipse/yasson/records/RecordTest.java +++ b/src/test/java/org/eclipse/yasson/records/RecordTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/yasson-tck/pom.xml b/yasson-tck/pom.xml index dea959820..1abbd05a0 100644 --- a/yasson-tck/pom.xml +++ b/yasson-tck/pom.xml @@ -11,11 +11,11 @@ 3.0.0 - 3.0.0-SNAPSHOT - 3.0.0 - 2.1.0 - 11 - 11 + 3.0.4-SNAPSHOT + 3.0.1 + 2.1.3 + 17 + 17 @@ -37,13 +37,13 @@ jakarta.json.bind jakarta.json.bind-api - 3.0.0 + ${jakarta.json.bind.version} provided jakarta.json jakarta.json-api - 2.1.0 + ${jakarta.json.version} provided @@ -55,13 +55,13 @@ org.jboss.weld.se weld-se-core - 5.0.1.Final + 6.0.0.Beta1 test org.jboss.arquillian.junit5 arquillian-junit5-container - 1.7.0.Alpha10 + 1.8.0.Final @@ -70,7 +70,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.2.0 + 3.6.1 copy @@ -105,22 +105,22 @@ maven-surefire-plugin - 3.0.0-M5 + 3.2.5 false true jakarta.json.bind:jakarta.json.bind-tck - ${project.build.directory}/jdk11-bundle + ${project.build.directory}/jdk-bundle - ${project.build.directory}/signaturedirectory/jakarta.json.bind-api.jar:${project.build.directory}/jdk11-bundle/java.base:${project.build.directory}/jdk11-bundle/java.rmi:${project.build.directory}/jdk11-bundle/java.sql:${project.build.directory}/jdk11-bundle/java.naming + ${project.build.directory}/signaturedirectory/jakarta.json.bind-api.jar:${project.build.directory}/jdk-bundle/java.base:${project.build.directory}/jdk-bundle/java.rmi:${project.build.directory}/jdk-bundle/java.sql:${project.build.directory}/jdk-bundle/java.naming maven-surefire-report-plugin - 3.0.0-M4 + 3.2.5 post-unit-test From 5fcac6578d9d7c9f378177a13ef0ca0775cddf4b Mon Sep 17 00:00:00 2001 From: Lukas Jungmann Date: Sat, 8 Jun 2024 12:19:47 +0200 Subject: [PATCH 11/12] Integrate parsson 1.1.7 (#644) --- .github/workflows/maven.yml | 6 +++--- pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9569655a0..ca961deb0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -37,10 +37,10 @@ jobs: - name: Copyright run: bash etc/copyright.sh - name: Checkstyle - run: mvn -B checkstyle:checkstyle + run: mvn -B checkstyle:checkstyle -Pstaging - name: Yasson install - run: mvn -U -C clean install -DskipTests + run: mvn -U -C clean install -Pstaging -DskipTests - name: Yasson tests run: mvn -U -B -C -Dmaven.javadoc.skip=true -Pstaging verify - name: JSONB-API TCK - run: cd yasson-tck && mvn -U -B test -DargLine="-Djava.locale.providers=COMPAT" + run: cd yasson-tck && mvn -U -B test -DargLine="-Djava.locale.providers=COMPAT" -Pstaging diff --git a/pom.xml b/pom.xml index b17b70c8a..1116c764c 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ 2.2.0 3.0.1 2.1.3 - 1.1.6 + 1.1.7 5.10.2 6.0.0.Beta1 From 14e68b6c01d9f93d6715f0e1fef4a9daf6aa1de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Kr=C3=A1l?= Date: Wed, 10 Jul 2024 16:05:32 +0200 Subject: [PATCH 12/12] JDK 11 compile target reverted (#645) JDK 11 compile target reverted Signed-off-by: David Kral --- .github/workflows/maven.yml | 6 +- pom.xml | 83 ++++++++++++++++++- .../internal/ClassMultiReleaseExtension.java | 21 +---- .../internal/ClassMultiReleaseExtension.java | 74 +++++++++++++++++ yasson-tck/pom.xml | 4 +- 5 files changed, 163 insertions(+), 25 deletions(-) create mode 100644 src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ca961deb0..3b210946b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,7 +21,7 @@ jobs: strategy: matrix: - java_version: [ 17, 21 ] + java_version: [ 11, 17, 21 ] steps: - name: Checkout for build @@ -30,9 +30,9 @@ jobs: fetch-depth: 0 - name: Set up compile JDK uses: actions/setup-java@v4 - with: + with: #Compile java needs to be the highest to ensure proper compilation of the multi-release jar distribution: 'temurin' - java-version: ${{ matrix.java_version }} + java-version: 17 cache: 'maven' - name: Copyright run: bash etc/copyright.sh diff --git a/pom.xml b/pom.xml index 1116c764c..a97891c7f 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ UTF-8 - 17 + 11 ${maven.compiler.release} @@ -298,6 +298,50 @@ + + jdk16 + + [16,) + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-testCompile + + 16 + 16 + + ${project.basedir}/src/test/java + ${project.basedir}/src/test/java16 + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + **/RecordTest.java + + + + + + @@ -309,6 +353,38 @@ maven-compiler-plugin ${maven-compiler-plugin.version} + + + default-compile + + compile + + + 11 + 11 + 11 + + + + default-testCompile + + 11 + + + + multi-release-compile-16 + + compile + + + 16 + + ${project.basedir}/src/main/java16 + + true + + + -Xlint:all @@ -322,6 +398,9 @@ ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + true + @@ -449,7 +528,7 @@ - [17,) + [11,) [3.6.0,) diff --git a/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java b/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java index 2f3d2dc44..72653cfd5 100644 --- a/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java +++ b/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java @@ -22,8 +22,6 @@ import org.eclipse.yasson.internal.model.JsonbCreator; import org.eclipse.yasson.internal.model.Property; -import org.eclipse.yasson.internal.properties.MessageKeys; -import org.eclipse.yasson.internal.properties.Messages; /** * Search for instance creator from other sources. @@ -36,38 +34,25 @@ private ClassMultiReleaseExtension() { } static boolean shouldTransformToPropertyName(Method method) { - return !method.getDeclaringClass().isRecord(); + return true; } static boolean isSpecialAccessorMethod(Method method, Map classProperties) { - return isRecord(method.getDeclaringClass()) - && method.getParameterCount() == 0 - && !void.class.equals(method.getReturnType()) - && classProperties.containsKey(method.getName()); + return false; } static JsonbCreator findCreator(Class clazz, Constructor[] declaredConstructors, AnnotationIntrospector introspector, PropertyNamingStrategy propertyNamingStrategy) { - if (clazz.isRecord()) { - if (declaredConstructors.length == 1) { - return introspector.createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy); - } - } return null; } public static boolean isRecord(Class clazz) { - return clazz.isRecord(); + return false; } public static Optional exceptionToThrow(Class clazz) { - if (clazz.isRecord()) { - if (clazz.getDeclaredConstructors().length > 1) { - return Optional.of(new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz))); - } - } return Optional.empty(); } diff --git a/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java b/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java new file mode 100644 index 000000000..2f3d2dc44 --- /dev/null +++ b/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +package org.eclipse.yasson.internal; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.Optional; + +import jakarta.json.bind.JsonbException; +import jakarta.json.bind.config.PropertyNamingStrategy; + +import org.eclipse.yasson.internal.model.JsonbCreator; +import org.eclipse.yasson.internal.model.Property; +import org.eclipse.yasson.internal.properties.MessageKeys; +import org.eclipse.yasson.internal.properties.Messages; + +/** + * Search for instance creator from other sources. + * Mainly intended to add extensibility for different java versions and new features. + */ +public class ClassMultiReleaseExtension { + + private ClassMultiReleaseExtension() { + throw new IllegalStateException("This class cannot be instantiated"); + } + + static boolean shouldTransformToPropertyName(Method method) { + return !method.getDeclaringClass().isRecord(); + } + + static boolean isSpecialAccessorMethod(Method method, Map classProperties) { + return isRecord(method.getDeclaringClass()) + && method.getParameterCount() == 0 + && !void.class.equals(method.getReturnType()) + && classProperties.containsKey(method.getName()); + } + + static JsonbCreator findCreator(Class clazz, + Constructor[] declaredConstructors, + AnnotationIntrospector introspector, + PropertyNamingStrategy propertyNamingStrategy) { + if (clazz.isRecord()) { + if (declaredConstructors.length == 1) { + return introspector.createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy); + } + } + return null; + } + + public static boolean isRecord(Class clazz) { + return clazz.isRecord(); + } + + public static Optional exceptionToThrow(Class clazz) { + if (clazz.isRecord()) { + if (clazz.getDeclaredConstructors().length > 1) { + return Optional.of(new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz))); + } + } + return Optional.empty(); + } + +} diff --git a/yasson-tck/pom.xml b/yasson-tck/pom.xml index 1abbd05a0..bd0d76e71 100644 --- a/yasson-tck/pom.xml +++ b/yasson-tck/pom.xml @@ -14,8 +14,8 @@ 3.0.4-SNAPSHOT 3.0.1 2.1.3 - 17 - 17 + 11 + 11