Merge pull request #727 from KyleAure/ensure-yassonParser-implements-all-API
test: ensure YassonParser implements JsonParser default methods
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 7038eba..6718d4e 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -4,5 +4,18 @@
directory: /
schedule:
interval: daily
-
-# TODO - add maven dependabot if community agrees it's useful
\ No newline at end of file
+
+ - package-ecosystem: maven
+ directory: /
+ schedule:
+ interval: daily
+
+ - package-ecosystem: maven
+ directory: /yasson-jmh
+ schedule:
+ interval: weekly
+
+ - package-ecosystem: maven
+ directory: /yasson-tck
+ schedule:
+ interval: weekly
\ No newline at end of file
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 6374c2a..e39f36e 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -29,7 +29,7 @@
strategy:
matrix:
- java_version: [ 11, 17, 21 ]
+ java_version: [ 17, 21, 25 ]
include:
- locale: en_US
# Use a different locale when running against one of the java versions
@@ -43,7 +43,7 @@
with:
fetch-depth: 0
- name: Set up compile JDK
- uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # v5.6.0
+ uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0
with: #Compile java needs to be the highest to ensure proper compilation of the multi-release jar
distribution: 'temurin'
java-version: 17
@@ -54,6 +54,8 @@
run: mvn -B checkstyle:checkstyle
- name: Yasson install
run: mvn -U -C clean install -DskipTests
+ - name: Yasson jmh package
+ run: mvn -U -C -f yasson-jmh/pom.xml clean package
- name: Yasson tests
run: |
export LANG_TAG="${{ matrix.locale }}"
@@ -62,5 +64,5 @@
-Duser.language="${LANG_TAG%%_*}" \
-Duser.country="${LANG_TAG##*_}" \
verify
- - name: JSONB-API TCK
+ - name: Jakarta JSON-B TCK
run: cd yasson-tck && mvn -U -B test -DargLine="-Djava.locale.providers=COMPAT"
diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml
index b90ad77..7977c1f 100644
--- a/.github/workflows/performance.yml
+++ b/.github/workflows/performance.yml
@@ -33,7 +33,7 @@
with:
fetch-depth: 0
- name: Set up compile JDK
- uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # v5.6.0
+ uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0
with: #Compile java needs to be the highest to ensure proper compilation of the multi-release jar
distribution: 'temurin'
java-version: 17
@@ -51,7 +51,7 @@
with:
name: Java JMH Benchmark
tool: 'jmh'
- output-file-path: jmh-result.json
+ output-file-path: yasson-jmh/jmh-result.json
github-token: ${{ secrets.GITHUB_TOKEN }}
# Enable deployment to GitHub Pages for continuous line graphs
diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml
index c9514ce..fb7b194 100644
--- a/.github/workflows/verify.yml
+++ b/.github/workflows/verify.yml
@@ -33,7 +33,7 @@
with:
fetch-depth: 0
- name: Set up compile JDK
- uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # v5.6.0
+ uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0
with: #Compile java needs to be the highest to ensure proper compilation of the multi-release jar
distribution: 'temurin'
java-version: 17
diff --git a/README.md b/README.md
index f04550b..f2f959a 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,11 @@
# Eclipse Yasson
-[](https://mvnrepository.com/artifact/org.eclipse/yasson)
+[](https://mvnrepository.com/artifact/org.eclipse.yasson/yasson)
<!-- TODO reenable once snapshots can be browsed via https://central.sonatype.com/service/rest/repository/browse/maven-snapshots
-[](https://jakarta.oss.sonatype.org/content/repositories/staging/org/eclipse/yasson/)
+[](https://jakarta.oss.sonatype.org/content/repositories/staging/org/eclipse/yasson/yasson/)
-->
[](https://gitter.im/eclipse/yasson)
-[](https://www.javadoc.io/doc/org.eclipse/yasson)
+[](https://www.javadoc.io/doc/org.eclipse.yasson/yasson)
[](https://github.com/eclipse-ee4j/yasson/actions/workflows/maven.yml?branch=main)
[](https://opensource.org/licenses/EPL-2.0)
diff --git a/pom.xml b/pom.xml
index fcbef73..7e3ab8b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,12 +20,12 @@
<parent>
<groupId>org.eclipse.ee4j</groupId>
<artifactId>project</artifactId>
- <version>2.0.4</version>
+ <version>2.0.5</version>
</parent>
- <groupId>org.eclipse</groupId>
+ <groupId>org.eclipse.yasson</groupId>
<artifactId>yasson</artifactId>
- <version>3.0.5-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Yasson</name>
@@ -35,42 +35,42 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.compiler.release>11</maven.compiler.release>
- <maven.compiler.target>11</maven.compiler.target>
- <maven.compiler.testRelease>${maven.compiler.release}</maven.compiler.testRelease>
+ <maven.compiler.release>17</maven.compiler.release>
<nexus.staging.repository>yasson-maven2-staging</nexus.staging.repository>
<!--Dependencies-->
- <hamcrest.version>2.2</hamcrest.version>
+ <hamcrest.version>3.0</hamcrest.version>
<!-- Jakarta API -->
+ <!-- TODO finalize versions to EE 12 -->
<jakarta.annotation-api.version>3.0.0</jakarta.annotation-api.version>
- <jakarta.el-api.version>6.0.0</jakarta.el-api.version>
+ <jakarta.el-api.version>6.1.0-M2</jakarta.el-api.version>
<jakarta.enterprise.cdi-api.version>4.1.0</jakarta.enterprise.cdi-api.version>
<jakarta.interceptor-api.version>2.2.0</jakarta.interceptor-api.version>
- <jakarta.json.bind.version>3.0.1</jakarta.json.bind.version>
+ <jakarta.json.bind.version>3.1.0-M1</jakarta.json.bind.version>
<jakarta.json.version>2.1.3</jakarta.json.version>
<!-- Jakarta Implementation -->
+ <!-- TODO update to EE 12 version-->
<jakarta.parson.version>1.1.9</jakarta.parson.version>
<!-- Test dependencies-->
- <junit-jupiter.version>5.14.4</junit-jupiter.version> <!-- TODO update to Junit 6 when running on Java 17+ -->
+ <junit-jupiter.version>6.1.2</junit-jupiter.version>
<weld-se-core.version>6.0.4.Final</weld-se-core.version>
<!--Plugins-->
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
- <buildnumber-maven-plugin.version>3.2.0</buildnumber-maven-plugin.version>
- <spotbugs-maven-plugin.version>4.8.5.0</spotbugs-maven-plugin.version>
+ <buildnumber-maven-plugin.version>3.3.0</buildnumber-maven-plugin.version>
+ <spotbugs-maven-plugin.version>4.10.3.0</spotbugs-maven-plugin.version>
<glassfish-copyright-maven-plugin.version>2.4</glassfish-copyright-maven-plugin.version>
<maven-bundle-plugin.version>5.1.9</maven-bundle-plugin.version>
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
- <maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
+ <maven-compiler-plugin.version>3.15.0</maven-compiler-plugin.version>
<maven-enforcer-plugin.version>3.4.1</maven-enforcer-plugin.version>
<maven-jar-plugin.version>3.4.1</maven-jar-plugin.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
- <maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
+ <maven-surefire-plugin.version>3.5.6</maven-surefire-plugin.version>
</properties>
<dependencyManagement>
@@ -312,50 +312,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>
@@ -366,39 +322,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
- <!-- defaults for compile and testCompile -->
- <executions>
- <execution>
- <id>default-compile</id>
- <goals>
- <goal>compile</goal>
- </goals>
- <configuration>
- <release>${maven.compiler.release}</release>
- <source>${maven.compiler.release}</source>
- <target>${maven.compiler.release}</target>
- </configuration>
- </execution>
- <execution>
- <id>default-testCompile</id>
- <configuration>
- <release>11</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>
<arg>-Xlint:all</arg>
@@ -473,7 +396,7 @@
java.beans;resolution:="optional",
*
</Import-Package>
- <Require-Capability>osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=11))"</Require-Capability>
+ <Require-Capability>osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=17))"</Require-Capability>
</instructions>
</configuration>
</execution>
@@ -496,7 +419,6 @@
<excludes>
<exclude>**/JavaxNamingExcludedTest.java</exclude>
<exclude>**/AnnotationIntrospectorWithoutOptionalModulesTest.java</exclude>
- <exclude>**/*Record*</exclude>
</excludes>
<argLine>
<!--Remove when CDI is updated to support modules
@@ -542,7 +464,7 @@
<configuration>
<rules>
<requireJavaVersion>
- <version>[11,)</version>
+ <version>[17,)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.6.0,)</version>
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..f83ed39 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
@@ -12,17 +12,6 @@
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;
-
/**
* Search for instance creator from other sources.
* Mainly intended to add extensibility for different java versions and new features.
@@ -33,27 +22,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..b63dc00 100644
--- a/src/main/java/org/eclipse/yasson/internal/ClassParser.java
+++ b/src/main/java/org/eclipse/yasson/internal/ClassParser.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
@@ -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/deserializer/types/UriDeserializer.java b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.java
index 26ea0fb..59b9425 100644
--- a/src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.java
+++ b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.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
@@ -14,8 +14,13 @@
import java.lang.reflect.Type;
import java.net.URI;
+import java.net.URISyntaxException;
+
+import jakarta.json.bind.JsonbException;
import org.eclipse.yasson.internal.DeserializationContextImpl;
+import org.eclipse.yasson.internal.properties.MessageKeys;
+import org.eclipse.yasson.internal.properties.Messages;
/**
* Deserializer of the {@link URI} type.
@@ -28,6 +33,10 @@
@Override
Object deserializeStringValue(String value, DeserializationContextImpl context, Type rType) {
- return URI.create(value);
+ try {
+ return new URI(value);
+ } catch (URISyntaxException e) {
+ throw new JsonbException(Messages.getMessage(MessageKeys.URI_PARSE_ERROR, value), e);
+ }
}
}
diff --git a/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java
index 54cd2f3..018448f 100644
--- a/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java
+++ b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.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
@@ -16,7 +16,11 @@
import java.net.MalformedURLException;
import java.net.URL;
+import jakarta.json.bind.JsonbException;
+
import org.eclipse.yasson.internal.DeserializationContextImpl;
+import org.eclipse.yasson.internal.properties.MessageKeys;
+import org.eclipse.yasson.internal.properties.Messages;
/**
* Deserializer of the {@link URL} type.
@@ -29,12 +33,10 @@
@Override
Object deserializeStringValue(String value, DeserializationContextImpl context, Type rType) {
- URL url = null;
try {
- url = new URL(value);
+ return new URL(value);
} catch (MalformedURLException e) {
- e.printStackTrace();
+ throw new JsonbException(Messages.getMessage(MessageKeys.URL_PARSE_ERROR, value), e);
}
- return url;
}
}
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/java/org/eclipse/yasson/internal/properties/MessageKeys.java b/src/main/java/org/eclipse/yasson/internal/properties/MessageKeys.java
index d08377c..fde557a 100644
--- a/src/main/java/org/eclipse/yasson/internal/properties/MessageKeys.java
+++ b/src/main/java/org/eclipse/yasson/internal/properties/MessageKeys.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
@@ -265,6 +265,14 @@
*/
ZONE_PARSE_ERROR("zoneParseError"),
/**
+ * There has been an error parsing a URI value.
+ */
+ URI_PARSE_ERROR("uriParseError"),
+ /**
+ * There has been an error parsing a URL value.
+ */
+ URL_PARSE_ERROR("urlParseError"),
+ /**
* {@link JsonbTransient} was not the only annotation on class property.
*/
JSONB_TRANSIENT_WITH_OTHER_ANNOTATIONS("jsonbTransientWithOtherAnnotations"),
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();
- }
-
-}
diff --git a/src/main/resources/yasson-messages.properties b/src/main/resources/yasson-messages.properties
index 4d22449..a059313 100644
--- a/src/main/resources/yasson-messages.properties
+++ b/src/main/resources/yasson-messages.properties
@@ -76,6 +76,8 @@
unknownJsonProperty=Json property {0} can not be mapped to a class {1}.
jsonbCreatorMissingProperty=JsonbCreator parameter {0} is missing in json document.
zoneParseError=Cannot parse zone from json value: {0}
+uriParseError=Cannot parse URI from json value: {0}
+urlParseError=Cannot parse URL from json value: {0}
jsonbTransientWithOtherAnnotations=JsonbTransient annotation cannot be used with other jsonb annotations on the same property.
nonParametrizedType=Type: {0} is not a parametrized type.
propertyNameClash=Property {0} clashes with property {1} by read or write name in class {2}.
diff --git a/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.java b/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.java
index 4963b12..afd68ba 100644
--- a/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.java
+++ b/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.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
@@ -15,6 +15,8 @@
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.net.URI;
+import java.net.URL;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -30,6 +32,7 @@
import org.eclipse.yasson.TestTypeToken;
import org.eclipse.yasson.defaultmapping.generics.model.GenericTestClass;
+import org.eclipse.yasson.defaultmapping.generics.model.ScalarValueWrapper;
import org.eclipse.yasson.defaultmapping.specific.model.ClassWithUnsupportedFields;
import org.eclipse.yasson.defaultmapping.specific.model.CustomUnsupportedInterface;
import org.eclipse.yasson.defaultmapping.specific.model.SupportedTypes;
@@ -69,7 +72,7 @@
String expected = "{\"customInterface\":{\"value\":\"value1\"}}";
assertEquals(expected, defaultJsonb.toJson(unsupported));
try {
- defaultJsonb.fromJson(expected, ClassWithUnsupportedFields.class);
+ defaultJsonb.fromJson(expected, ClassWithUnsupportedFields.class);
fail("Should report an error");
} catch (JsonbException e) {
assertTrue(e.getMessage().contains("Cannot infer a type"));
@@ -133,11 +136,11 @@
@Test
public void testMissingFieldIgnored() {
- assertThrows(JsonbException.class, () -> {
- Jsonb defaultConfig = JsonbBuilder.create(new JsonbConfig().setProperty(FAIL_ON_UNKNOWN_PROPERTIES, true));
- String json = "{\"nestedPojo\":{\"integerValue\":10,\"missingField\":5},\"optionalLong\":11}";
- SupportedTypes result = defaultConfig.fromJson(json, SupportedTypes.class);
- });
+ assertThrows(JsonbException.class, () -> {
+ Jsonb defaultConfig = JsonbBuilder.create(new JsonbConfig().setProperty(FAIL_ON_UNKNOWN_PROPERTIES, true));
+ String json = "{\"nestedPojo\":{\"integerValue\":10,\"missingField\":5},\"optionalLong\":11}";
+ SupportedTypes result = defaultConfig.fromJson(json, SupportedTypes.class);
+ });
}
@Test
@@ -223,11 +226,33 @@
Type type = new TestTypeToken<GenericTestClass<OptionalLong, OptionalLong>>(){}.getType();
assertFail("{\"field1\":\"\"}", type,"field1", Long.class); //We are reusing Long deserializer
}
+
+ @Test
+ public void testMalformedURL() {
+ Type type = new TestTypeToken<ScalarValueWrapper<URL>>(){}.getType();
+ try {
+ defaultJsonb.fromJson("{\"value\":\"www.oracle.com\"}", type);
+ fail("Expected to catch JsonbException but did not");
+ } catch (JsonbException e) {
+ assertTrue(e.getMessage().contains("Cannot parse URL") && e.getMessage().contains("www.oracle.com"));
+ }
+ }
+
+ @Test
+ public void testMalformedURI() {
+ Type type = new TestTypeToken<ScalarValueWrapper<URI>>(){}.getType();
+ try {
+ defaultJsonb.fromJson("{\"value\":\"www .oracle .com\"}", type);
+ fail("Expected to catch JsonbException but did not");
+ } catch (JsonbException e) {
+ assertTrue(e.getMessage().contains("Cannot parse URI") && e.getMessage().contains("www .oracle .com"));
+ }
+ }
private void assertFail(String json, Type type, String failureProperty, Class<?> failurePropertyClass) {
try {
- defaultJsonb.fromJson(json, type);
- fail();
+ defaultJsonb.fromJson(json, type);
+ fail("Expected to catch JsonbException but did not");
} catch (JsonbException e) {
if(!e.getMessage().contains(failureProperty) || !e.getMessage().contains(failurePropertyClass.getName())) {
fail("Expected error message to contain '" + failureProperty + "' and '" + failurePropertyClass.getName() + "', but was: " +
diff --git a/yasson-jmh/pom.xml b/yasson-jmh/pom.xml
index 61d3046..498d548 100644
--- a/yasson-jmh/pom.xml
+++ b/yasson-jmh/pom.xml
@@ -8,19 +8,22 @@
<parent>
<groupId>org.eclipse.ee4j</groupId>
<artifactId>project</artifactId>
- <version>2.0.4</version>
+ <version>2.0.5</version>
</parent>
<groupId>org.eclipse.yasson</groupId>
<artifactId>yasson-jmh</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<description>This is a performance testing project for Yasson. It leverages a JMH technology.
See https://openjdk.java.net/projects/code-tools/jmh/.
</description>
<properties>
- <jmh.version>1.21</jmh.version>
- <yasson.version>3.0.5-SNAPSHOT</yasson.version>
+ <maven.compiler.release>17</maven.compiler.release>
+
+ <jmh.version>1.37</jmh.version>
+ <yasson.version>${project.version}</yasson.version>
+ <maven-shade-plugin.version>3.6.2</maven-shade-plugin.version>
</properties>
@@ -36,7 +39,7 @@
<version>${jmh.version}</version>
</dependency>
<dependency>
- <groupId>org.eclipse</groupId>
+ <groupId>org.eclipse.yasson</groupId>
<artifactId>yasson</artifactId>
<version>${yasson.version}</version>
</dependency>
@@ -60,16 +63,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>11</source>
- <target>11</target>
- </configuration>
</plugin>
<!--run `java -jar yasson-jmh.jar -h` for help -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
- <version>3.2.1</version>
+ <version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
diff --git a/yasson-tck/pom.xml b/yasson-tck/pom.xml
index bab505d..7ab61a9 100644
--- a/yasson-tck/pom.xml
+++ b/yasson-tck/pom.xml
@@ -8,35 +8,36 @@
<parent>
<groupId>org.eclipse.ee4j</groupId>
<artifactId>project</artifactId>
- <version>2.0.4</version>
+ <version>2.0.5</version>
<relativePath/>
</parent>
- <groupId>org.eclipse</groupId>
+ <groupId>org.eclipse.yasson</groupId>
<artifactId>yasson-tck</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<properties>
- <maven.compiler.source>11</maven.compiler.source>
- <maven.compiler.target>11</maven.compiler.target>
+ <maven.compiler.release>17</maven.compiler.release>
<!-- API Versions -->
+ <!-- TODO update to EE 12 final versions -->
<jakarta.json.version>2.1.3</jakarta.json.version> <!-- EE10 -->
- <jakarta.json.bind.version>3.0.1</jakarta.json.bind.version> <!-- EE10 -->
+ <jakarta.json.bind.version>3.1.0-M1</jakarta.json.bind.version>
<!-- IMPL Versions -->
- <jsonb.tck.version>3.0.0</jsonb.tck.version> <!-- EE10 -->
- <yasson.version>3.0.5-SNAPSHOT</yasson.version> <!-- EE10 -->
+ <!-- TODO update to EE 12 final versions -->
+ <jsonb.tck.version>3.1.0-M1</jsonb.tck.version>
+ <yasson.version>${project.version}</yasson.version>
<!-- Test Versions -->
- <junit-jupiter.version>5.14.4</junit-jupiter.version> <!-- TODO update to Junit 6 when running on Java 17+ -->
+ <junit-jupiter.version>6.1.1</junit-jupiter.version>
<weld-se-core.version>6.0.4.Final</weld-se-core.version>
- <arquillian-junit5-container.version>1.8.0.Final</arquillian-junit5-container.version>
+ <arquillian-junit5-container.version>1.10.2.Final</arquillian-junit5-container.version>
<!-- Plugin Versions -->
- <maven-dependency-plugin.version>3.6.1</maven-dependency-plugin.version>
- <maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
- <maven-surefire-report-plugin.version>3.2.5</maven-surefire-report-plugin.version>
+ <maven-dependency-plugin.version>3.11.0</maven-dependency-plugin.version>
+ <maven-surefire-plugin.version>3.5.6</maven-surefire-plugin.version>
+ <maven-surefire-report-plugin.version>3.5.6</maven-surefire-report-plugin.version>
</properties>
<dependencies>
@@ -59,7 +60,7 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.eclipse</groupId>
+ <groupId>org.eclipse.yasson</groupId>
<artifactId>yasson</artifactId>
<version>${yasson.version}</version>
<scope>test</scope>