Keys for HAL's _embedded document and link relations do not follow the Jackson PropertyNamingStrategy configured
See original GitHub issueI have two beans in my configuration:
@Bean
public ObjectMapper getObjectMapper() {
val objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(SNAKE_CASE);
objectMapper.registerModule(new AfterburnerModule());
objectMapper.registerModule(new ProblemModule());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper;
}
@Bean
public Jackson2ObjectMapperBuilder getJackson2ObjectMapperBuilder() {
val jackson2ObjectMapperBuilder = new Jackson2ObjectMapperBuilder();
jackson2ObjectMapperBuilder.propertyNamingStrategy(SNAKE_CASE);
return jackson2ObjectMapperBuilder;
}
The problem is my response objects are still CAMEL_CASE
so I don’t think Hateaos is using the correct bean. Am I writing the correct bean to change the naming strategy so that my response is entity_models
and not entityModels
?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Jackson is ignoring spring.jackson.properties in my spring ...
I had @EnableWebMvc annotation in one of the classes (ExceptionHandler) in my Application (face-palm!). But, as per this issue,.
Read more >More Jackson Annotations - Baeldung
The @JsonAppend annotation is used to add virtual properties to an object in addition to regular ones when that object is serialized. This...
Read more >PropertyNamingStrategy (jackson-databind 2.7.0 API)
Class that defines how names of JSON properties ("external names") are derived from names of POJO methods and fields ("internal names"), in cases...
Read more >Jackson Property Custom Naming Strategy - DZone
This quick tutorial demonstrates how to use built-in property naming strategies and how to create a custom one. Property Naming. @JsonProperty ( ...
Read more >Spring Jackson property naming strategy - Java Developer Zone
Jackson is a very popular library to convert Java object to JSON. while converting POJO to JSON, It will consider property name will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, Marvin. That’s a lot of Interesting details.
If I read the spec correctly, the links only need to be absolute URIs if they’re used within a
Link
header. Also, the general rule seems to define either thereg-rel-type
format or a URI.reg-rel-type
is the format which registered relation types have to follow but that doesn’t mean link relation types need to be registered or URIs. Happy to learn that I’m wrong here 😃. That said, HAL CURIE mechanism allows to basically interpret all link relations as URIs by producing short versions of it that are valid URIs themselves.What’s puzzling, too is that
reg-rel-type
only defines lower case characters to be allowed but the IANA list containing a few that use camel case.I definitely take this as a vote for consistency here, thanks!
From a spec point of view, the link relation type defines the kind of relation between to resources. So there’s no reason why a link relation type for an embedded resource should differ from a link relation type describing a link - the relation is semantically the same.
From a practical point of view, I’d also definitely argue in favor of consistent link relation types for
_links
and_embedded
. We relied on this convention in our REST client to selectively optimize requests by embedding resources that were previously only linked in a represenation without having to change anything in the client (see implementation here).In general, I’d like to point out that the Web Linking spec (RFC 8288) requires extension link relation types (meaning, link relation types that are not registered through IANA) to be URIs and the JSON-HAL spec references that RFC also in regards to
_embedded
. So if you want to be nitpicky, neitherentityModelList
norentity_model_list
are valid link relation types in the first place. But I guess in practice nobody cares about that … 🤷♂️