diff --git a/pom.xml b/pom.xml index bc19ff1f0..f61c567f3 100644 --- a/pom.xml +++ b/pom.xml @@ -285,12 +285,11 @@ org.apache.maven.plugins maven-compiler-plugin - 3.13.0 default-testCompile - 16 + 17 ${project.basedir}/src/test/java ${project.basedir}/src/test/java16 @@ -394,28 +393,15 @@ compile - 11 - 11 - 11 + 17 + 17 + 17 default-testCompile - 11 - - - - multi-release-compile-16 - - compile - - - 16 - - ${project.basedir}/src/main/java16 - - true + 17 @@ -471,7 +457,7 @@ --add-modules jakarta.json.bind,jakarta.json - 11 + 17 @@ -591,7 +577,7 @@ - [11,) + [17,) [3.3.9,) @@ -714,7 +700,6 @@ org.codehaus.mojo findbugs-maven-plugin - ${findbugs-maven-plugin.version} 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/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/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