So I need help in using java eclipse collections as part of the response using the spring boot Response Entity JSON . I have tried using the generic way but I get a response exception error that it failed to convert to java ArrayList type so can anyone provide an example for a normal rest endpoint that uses eclipse collections data instead of java collections list?
here is an example code
@GetMapping("/list")
public ResponseEntity<MutableList<Person>> getData() {
return ResponseEntity.ok(Map.of(
"success", true,
"data", Map.of(
"users", personService.getUsers()
)
));
}
Instructions for enabling eclipse-collections Jackson module that adds Json serialization support for Eclipse Collection Types:
By default Spring MVC MappingJackson2HttpMessageConverter will create its own ObjectMapper with default options using Jackson2ObjectMapperBuilder. As per Spring Boot docs 76.3 Customize the Jackson ObjectMapper chapter:
Any beans of type com.fasterxml.jackson.databind.Module are automatically registered with the auto-configured Jackson2ObjectMapperBuilder and are applied to any ObjectMapper instances that it creates. This provides a global mechanism for contributing custom modules when you add new features to your application.
so it should be enough to register eclipse collections module as a bean:
@Bean
public EclipseCollectionsModule eclipseCollectionsModule()
{
return new EclipseCollectionsModule();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With