Deserialize creators and records with the CASE_INSENSITIVE strategy With CASE_INSENSITIVE, the deserializers and default values of creator parameters are keyed by lower-cased names and the JSON keys are lower-cased, but JsonbCreatorDeserializer kept the creator parameter names as they are. A parameter name with an uppercase letter was then never matched, and deserialization failed with a NullPointerException when looking up its default value. Rename the creator parameter names in the same way. Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
diff --git a/src/main/java/org/eclipse/yasson/internal/deserializer/JsonbCreatorDeserializer.java b/src/main/java/org/eclipse/yasson/internal/deserializer/JsonbCreatorDeserializer.java index 9231c50..6dd9da9 100644 --- a/src/main/java/org/eclipse/yasson/internal/deserializer/JsonbCreatorDeserializer.java +++ b/src/main/java/org/eclipse/yasson/internal/deserializer/JsonbCreatorDeserializer.java
@@ -1,5 +1,6 @@ /* * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -55,7 +56,8 @@ Set<String> ignoredProperties) { this.propertyDeserializerChains = propertyDeserializerChains; this.defaultCreatorValues = defaultCreatorValues; - this.creatorParams = Arrays.stream(creator.getParams()).map(CreatorModel::getName).collect(Collectors.toList()); + // Renamed like the keys of propertyDeserializerChains and defaultCreatorValues, and the JSON keys + this.creatorParams = Arrays.stream(creator.getParams()).map(CreatorModel::getName).map(renamer).collect(Collectors.toList()); this.ignoredProperties = Set.copyOf(ignoredProperties); this.creator = creator; this.clazz = clazz;
diff --git a/src/test/java/org/eclipse/yasson/internal/model/customization/naming/PropertyNamingStrategyTest.java b/src/test/java/org/eclipse/yasson/internal/model/customization/naming/PropertyNamingStrategyTest.java index 33c0c60..d282097 100644 --- a/src/test/java/org/eclipse/yasson/internal/model/customization/naming/PropertyNamingStrategyTest.java +++ b/src/test/java/org/eclipse/yasson/internal/model/customization/naming/PropertyNamingStrategyTest.java
@@ -1,5 +1,6 @@ /* * Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -18,9 +19,12 @@ import jakarta.json.bind.Jsonb; import jakarta.json.bind.JsonbBuilder; import jakarta.json.bind.JsonbConfig; +import jakarta.json.bind.annotation.JsonbCreator; +import jakarta.json.bind.annotation.JsonbProperty; import jakarta.json.bind.config.PropertyNamingStrategy; import org.eclipse.yasson.internal.model.customization.StrategiesProvider; +import org.eclipse.yasson.records.Car; /** * Tests naming strategies. @@ -98,6 +102,44 @@ assertResult(result); } + public static class Person { + private final String firstName; + private final int birthYear; + + @JsonbCreator + public Person(@JsonbProperty("firstName") String firstName, @JsonbProperty("birthYear") int birthYear) { + this.firstName = firstName; + this.birthYear = birthYear; + } + + public String getFirstName() { + return firstName; + } + + public int getBirthYear() { + return birthYear; + } + } + + @Test + public void testCaseInsensitiveWithCreator() throws Exception { + try (Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.CASE_INSENSITIVE))) { + assertEquals("Ann", jsonb.fromJson("{\"firstName\":\"Ann\"}", Person.class).getFirstName()); + assertEquals("Ann", jsonb.fromJson("{\"FIRSTNAME\":\"Ann\"}", Person.class).getFirstName()); + assertEquals(1990, jsonb.fromJson("{\"BirthYear\":1990}", Person.class).getBirthYear()); + Person missing = jsonb.fromJson("{}", Person.class); + assertNull(missing.getFirstName()); + assertEquals(0, missing.getBirthYear()); + } + } + + @Test + public void testCaseInsensitiveWithRecord() throws Exception { + try (Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.CASE_INSENSITIVE))) { + assertEquals(new Car("skoda", "red"), jsonb.fromJson("{\"TYPECHANGED\":\"skoda\",\"colorChanged\":\"red\"}", Car.class)); + } + } + @Test public void testIdentityCaseSensitive() { Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.IDENTITY));