refactor: remove multirelease jar components for java 16
diff --git a/pom.xml b/pom.xml index 70f7c8c..3c9ef81 100644 --- a/pom.xml +++ b/pom.xml
@@ -314,50 +314,6 @@ </plugins> </build> </profile> - <profile> - <id>jdk16</id> - <activation> - <jdk>[16,)</jdk> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <executions> - <execution> - <id>default-testCompile</id> - <configuration> - <release>16</release> - <testRelease>16</testRelease> - <compileSourceRoots> - <compileSourceRoot>${project.basedir}/src/test/java</compileSourceRoot> - <compileSourceRoot>${project.basedir}/src/test/java16</compileSourceRoot> - </compileSourceRoots> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - </execution> - </executions> - <configuration> - <includes> - <include>**/RecordTest.java</include> - </includes> - </configuration> - </plugin> - </plugins> - </build> - </profile> </profiles> <build> @@ -387,19 +343,6 @@ <release>17</release> </configuration> </execution> - <execution> - <id>multi-release-compile-16</id> - <goals> - <goal>compile</goal> - </goals> - <configuration> - <release>16</release> - <compileSourceRoots> - <compileSourceRoot>${project.basedir}/src/main/java16</compileSourceRoot> - </compileSourceRoots> - <multiReleaseOutput>true</multiReleaseOutput> - </configuration> - </execution> </executions> <configuration> <compilerArgs> @@ -411,14 +354,6 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>${maven-jar-plugin.version}</version> - <configuration> - <archive> - <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> - <manifestEntries> - <Multi-Release>true</Multi-Release> - </manifestEntries> - </archive> - </configuration> </plugin> <plugin> <!-- This plugin generates the buildNumber property used in maven-bundle-plugin --> @@ -498,7 +433,6 @@ <excludes> <exclude>**/JavaxNamingExcludedTest.java</exclude> <exclude>**/AnnotationIntrospectorWithoutOptionalModulesTest.java</exclude> - <exclude>**/*Record*</exclude> </excludes> <argLine> <!--Remove when CDI is updated to support modules
diff --git a/src/main/java/org/eclipse/yasson/internal/AnnotationIntrospector.java b/src/main/java/org/eclipse/yasson/internal/AnnotationIntrospector.java index 36c2943..2228c51 100644 --- a/src/main/java/org/eclipse/yasson/internal/AnnotationIntrospector.java +++ b/src/main/java/org/eclipse/yasson/internal/AnnotationIntrospector.java
@@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026 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 @@ -186,7 +186,9 @@ } } if (jsonbCreator == null) { - jsonbCreator = ClassMultiReleaseExtension.findCreator(clazz, declaredConstructors, this, propertyNamingStrategy); + if (clazz.isRecord() && declaredConstructors.length == 1) { + jsonbCreator = createJsonbCreator(declaredConstructors[0], null, clazz, propertyNamingStrategy); + } if (jsonbCreator == null) { jsonbCreator = constructorPropertiesIntrospector.getCreator(declaredConstructors); }
diff --git a/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java b/src/main/java/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java index 72653cf..99dd434 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, 2024 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026 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. @@ -33,27 +35,5 @@ throw new IllegalStateException("This class cannot be instantiated"); } - static boolean shouldTransformToPropertyName(Method method) { - return true; - } - - static boolean isSpecialAccessorMethod(Method method, Map<String, Property> classProperties) { - return false; - } - - static JsonbCreator findCreator(Class<?> clazz, - Constructor<?>[] declaredConstructors, - AnnotationIntrospector introspector, - PropertyNamingStrategy propertyNamingStrategy) { - return null; - } - - public static boolean isRecord(Class<?> clazz) { - return false; - } - - public static Optional<JsonbException> exceptionToThrow(Class<?> clazz) { - return Optional.empty(); - } - + // Currently is unused - but could be used in the future. }
diff --git a/src/main/java/org/eclipse/yasson/internal/ClassParser.java b/src/main/java/org/eclipse/yasson/internal/ClassParser.java index 4adce65..ab7b1e5 100644 --- a/src/main/java/org/eclipse/yasson/internal/ClassParser.java +++ b/src/main/java/org/eclipse/yasson/internal/ClassParser.java
@@ -198,14 +198,14 @@ for (Method method : declaredMethods) { String name = method.getName(); //isBridge method filters out methods inherited from interfaces - boolean isAccessorMethod = ClassMultiReleaseExtension.isSpecialAccessorMethod(method, classProperties) + boolean isAccessorMethod = isSpecialAccessorMethod(method, classProperties) || isPropertyMethod(method); if (!isAccessorMethod || method.isBridge() || isSpecialCaseMethod(clazz, method)) { continue; } - final String propertyName = ClassMultiReleaseExtension.shouldTransformToPropertyName(method) - ? toPropertyMethod(name) - : name; + final String propertyName = method.getDeclaringClass().isRecord() + ? name + : toPropertyMethod(name); registerMethod(propertyName, method, classElement, classProperties); } @@ -265,6 +265,13 @@ return isGetter(m) || isSetter(m); } + private static boolean isSpecialAccessorMethod(Method method, Map<String, Property> classProperties) { + return method.getDeclaringClass().isRecord() + && method.getParameterCount() == 0 + && !void.class.equals(method.getReturnType()) + && classProperties.containsKey(method.getName()); + } + private static void parseFields(JsonbAnnotatedElement<Class<?>> classElement, Map<String, Property> classProperties) { Field[] declaredFields = AccessController.doPrivileged( (PrivilegedAction<Field[]>) () -> classElement.getElement().getDeclaredFields());
diff --git a/src/main/java/org/eclipse/yasson/internal/deserializer/DefaultObjectInstanceCreator.java b/src/main/java/org/eclipse/yasson/internal/deserializer/DefaultObjectInstanceCreator.java index 822da18..d4358ab 100644 --- a/src/main/java/org/eclipse/yasson/internal/deserializer/DefaultObjectInstanceCreator.java +++ b/src/main/java/org/eclipse/yasson/internal/deserializer/DefaultObjectInstanceCreator.java
@@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026 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 @@ -17,7 +17,6 @@ import jakarta.json.bind.JsonbException; import jakarta.json.stream.JsonParser; -import org.eclipse.yasson.internal.ClassMultiReleaseExtension; import org.eclipse.yasson.internal.DeserializationContextImpl; import org.eclipse.yasson.internal.ReflectionUtils; import org.eclipse.yasson.internal.properties.MessageKeys; @@ -40,8 +39,11 @@ if (clazz.isInterface()) { this.exception = new JsonbException(Messages.getMessage(MessageKeys.INFER_TYPE_FOR_UNMARSHALL, clazz.getName())); } else if (defaultConstructor == null) { - this.exception = ClassMultiReleaseExtension.exceptionToThrow(clazz) - .orElse(new JsonbException(Messages.getMessage(MessageKeys.NO_DEFAULT_CONSTRUCTOR, clazz))); + if (clazz.isRecord() && clazz.getDeclaredConstructors().length > 1) { + this.exception = new JsonbException(Messages.getMessage(MessageKeys.RECORD_MULTIPLE_CONSTRUCTORS, clazz)); + } else { + this.exception = new JsonbException(Messages.getMessage(MessageKeys.NO_DEFAULT_CONSTRUCTOR, clazz)); + } } else { this.exception = null; }
diff --git a/src/main/java/org/eclipse/yasson/internal/model/ClassModel.java b/src/main/java/org/eclipse/yasson/internal/model/ClassModel.java index 8cdbdde..af7765b 100644 --- a/src/main/java/org/eclipse/yasson/internal/model/ClassModel.java +++ b/src/main/java/org/eclipse/yasson/internal/model/ClassModel.java
@@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026 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 @@ -23,7 +23,6 @@ import jakarta.json.bind.config.PropertyNamingStrategy; -import org.eclipse.yasson.internal.ClassMultiReleaseExtension; import org.eclipse.yasson.internal.ReflectionUtils; import org.eclipse.yasson.internal.model.customization.ClassCustomization; import org.eclipse.yasson.internal.model.customization.StrategiesProvider; @@ -191,7 +190,7 @@ // Example: Deserialization into Map won't use this constructor, and therefore never needs to call this method. // Note: Null is a valid result and needs to be cached. if (!isInitialized.get()) { - if (ClassMultiReleaseExtension.isRecord(clazz)) { + if (clazz.isRecord()) { //No default constructor should be used in case of records defaultConstructor = null; } else {
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 2f3d2dc..0000000 --- a/src/main/java16/org/eclipse/yasson/internal/ClassMultiReleaseExtension.java +++ /dev/null
@@ -1,74 +0,0 @@ -/* - * 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<String, Property> 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<JsonbException> 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(); - } - -}