diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ca961deb..3b210946 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 1116c764..a97891c7 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 2f3d2dc4..72653cfd 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 00000000..2f3d2dc4 --- /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 1abbd05a..bd0d76e7 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