spring-projects / spring-projects/spring-hateoas
Hal rendering Jackson2HalModule for custom type is not working
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
Http converter renders data as regular json instead (i.e. "links" instead of "_links"). If set jackson module to collectionjson or uber everything seems to work fine.
Configuration
@Configuration
public class ContactDirMediaTypeConfiguration implements HypermediaMappingInformation {
@Override
public Module getJacksonModule() {
return new Jackson2HalModule();
}
@Override
public List<MediaType> getMediaTypes() {
return MediaType.parseMediaTypes("application/vnd.contactdir.v1+json, application/hal+json");
}
}
configuration provider
public class ContactDirMediaTypeConfigurationProvider implements MediaTypeConfigurationProvider {
@Override
public Class<? extends HypermediaMappingInformation> getConfiguration() {
return ContactDirMediaTypeConfiguration.class;
}
@Override
public boolean supportsAny(Collection<MediaType> mediaTypes) {
return true;
}
}
controller
@RestController
@RequestMapping("/api")
public class ContactListController {
@GetMapping(path = "/contacts",
produces = {"application/vnd.contactdir.v1+json", "application/hal+json"})
public ResponseEntity<ContactDto> getAllContacts() {
ContactDto dto = new ContactDto().setName("dfsfdsfsdf");
dto.add(linkTo(ContactListController.class).withSelfRel());
return new ResponseEntity<>(dto, HttpStatus.OK);
}
}
Project reproducing the problem
Is it a bug or (what is more possible) did I miss something?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproducing project and its ContactDirMediaTypeConfiguration, MediaTypeConfigurationProvider, and ContactListController entry points. Reproduce the response for the custom media type, then trace how Jackson2HalModule is registered compared with the collectionjson and uber modules. Done means the custom media type renders HAL links as "_links" rather than "links".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100