Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set naming strategy to lower camel case for one class

My project already has an ObjectMapper defined, as follows

final ObjectMapper mapper = new ObjectMapper();
// some other settings here
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

Most classes in my project in fact use SNAKE_CASE, and everything's peachy. Now I have a class that the downstream returns in lower camel case. I tried using @JsonNaming(PropertyNamingStrategy.LowerCamelCaseStrategy) on my class. If it existed that'd work, but nothing like that seems to exist inside PropertyNamingStrategy.

All I find referencing lower camel case is the constant PropertyNamingStrategy.LOWER_CAMEL_CASE which is only used like in the top snippet it seems, and I definitely don't want to override the project settings here, since almost all classes use snake case.

Of course, I could slap a @JsonProperty('propertyInLowerCamelCase') on every property in the class, but there's quite a few, and that seems like it shouldn't be necessary.

like image 289
jessechisel126 Avatar asked Jan 20 '26 20:01

jessechisel126


1 Answers

To enforce lowerCamelCase, you can use the annotation

@JsonNaming(PropertyNamingStrategy::class)

This enforces the default naming strategy (lowerCamelCase) and overrides a globally configured naming strategy.

like image 105
physicsGuy Avatar answered Jan 23 '26 11:01

physicsGuy