59
59
import jakarta .json .bind .annotation .JsonbTypeInfo ;
60
60
import jakarta .json .bind .annotation .JsonbTypeSerializer ;
61
61
import jakarta .json .bind .annotation .JsonbVisibility ;
62
+ import jakarta .json .bind .config .PropertyNamingStrategy ;
62
63
import jakarta .json .bind .config .PropertyVisibilityStrategy ;
63
64
import jakarta .json .bind .serializer .JsonbDeserializer ;
64
65
import jakarta .json .bind .serializer .JsonbSerializer ;
@@ -152,10 +153,12 @@ private String getJsonbPropertyCustomizedName(Property property, JsonbAnnotatedE
152
153
/**
153
154
* Searches for JsonbCreator annotation on constructors and static methods.
154
155
*
155
- * @param clazz class to search
156
+ * @param clazz class to search
157
+ * @param propertyNamingStrategy The naming strategy to use for the ${@code JsonbConstructor} annotation,
158
+ * if set and no {@code JsonbProperty} annotations are present.
156
159
* @return JsonbCreator metadata object
157
160
*/
158
- public JsonbCreator getCreator (Class <?> clazz ) {
161
+ public JsonbCreator getCreator (Class <?> clazz , PropertyNamingStrategy propertyNamingStrategy ) {
159
162
JsonbCreator jsonbCreator = null ;
160
163
Constructor <?>[] declaredConstructors =
161
164
AccessController .doPrivileged ((PrivilegedAction <Constructor <?>[]>) clazz ::getDeclaredConstructors );
@@ -164,7 +167,7 @@ public JsonbCreator getCreator(Class<?> clazz) {
164
167
final jakarta .json .bind .annotation .JsonbCreator annot = findAnnotation (constructor .getDeclaredAnnotations (),
165
168
jakarta .json .bind .annotation .JsonbCreator .class );
166
169
if (annot != null ) {
167
- jsonbCreator = createJsonbCreator (constructor , jsonbCreator , clazz );
170
+ jsonbCreator = createJsonbCreator (constructor , jsonbCreator , clazz , propertyNamingStrategy );
168
171
}
169
172
}
170
173
@@ -179,19 +182,19 @@ public JsonbCreator getCreator(Class<?> clazz) {
179
182
method ,
180
183
clazz ));
181
184
}
182
- jsonbCreator = createJsonbCreator (method , jsonbCreator , clazz );
185
+ jsonbCreator = createJsonbCreator (method , jsonbCreator , clazz , propertyNamingStrategy );
183
186
}
184
187
}
185
188
if (jsonbCreator == null ) {
186
- jsonbCreator = ClassMultiReleaseExtension .findCreator (clazz , declaredConstructors , this );
189
+ jsonbCreator = ClassMultiReleaseExtension .findCreator (clazz , declaredConstructors , this , propertyNamingStrategy );
187
190
if (jsonbCreator == null ) {
188
191
jsonbCreator = constructorPropertiesIntrospector .getCreator (declaredConstructors );
189
192
}
190
193
}
191
194
return jsonbCreator ;
192
195
}
193
196
194
- JsonbCreator createJsonbCreator (Executable executable , JsonbCreator existing , Class <?> clazz ) {
197
+ JsonbCreator createJsonbCreator (Executable executable , JsonbCreator existing , Class <?> clazz , PropertyNamingStrategy propertyNamingStrategy ) {
195
198
if (existing != null ) {
196
199
throw new JsonbException (Messages .getMessage (MessageKeys .MULTIPLE_JSONB_CREATORS , clazz ));
197
200
}
@@ -205,7 +208,8 @@ JsonbCreator createJsonbCreator(Executable executable, JsonbCreator existing, Cl
205
208
if (jsonbPropertyAnnotation != null && !jsonbPropertyAnnotation .value ().isEmpty ()) {
206
209
creatorModels [i ] = new CreatorModel (jsonbPropertyAnnotation .value (), parameter , executable , jsonbContext );
207
210
} else {
208
- creatorModels [i ] = new CreatorModel (parameter .getName (), parameter , executable , jsonbContext );
211
+ final String translatedParameterName = propertyNamingStrategy .translateName (parameter .getName ());
212
+ creatorModels [i ] = new CreatorModel (translatedParameterName , parameter , executable , jsonbContext );
209
213
}
210
214
}
211
215
@@ -779,16 +783,19 @@ public Set<Class<?>> collectInterfaces(Class<?> cls) {
779
783
/**
780
784
* Processes customizations.
781
785
*
782
- * @param clsElement Element to process.
786
+ * @param clsElement Element to process.
787
+ * @param propertyNamingStrategy The naming strategy to use for the ${@code JsonbConstructor} annotation,
788
+ * if set and no {@code JsonbProperty} annotations are present.
783
789
* @return Populated {@link ClassCustomization} instance.
784
790
*/
785
791
public ClassCustomization introspectCustomization (JsonbAnnotatedElement <Class <?>> clsElement ,
786
- ClassCustomization parentCustomization ) {
792
+ ClassCustomization parentCustomization ,
793
+ PropertyNamingStrategy propertyNamingStrategy ) {
787
794
return ClassCustomization .builder ()
788
795
.nillable (isClassNillable (clsElement ))
789
796
.dateTimeFormatter (getJsonbDateFormat (clsElement ))
790
797
.numberFormatter (getJsonbNumberFormat (clsElement ))
791
- .creator (getCreator (clsElement .getElement ()))
798
+ .creator (getCreator (clsElement .getElement (), propertyNamingStrategy ))
792
799
.propertyOrder (getPropertyOrder (clsElement ))
793
800
.adapterBinding (getAdapterBinding (clsElement ))
794
801
.serializerBinding (getSerializerBinding (clsElement ))
0 commit comments