'Unable to serialize using SerializationFeature.WRAP_ROOT_VALUE using Spring Boot
I'm using Spring Boot 2.2.2 + Swagger2 v2.9.2 and I'm trying to achieve something really basic - I would like to serialize the REST responses using a SerializationFeature.WRAP_ROOT_VALUE.
I can't make it work!
I'm tried to do this:
spring.jackson.serialization.wrap-root-value=true
in my application.properties
and also tried to configure a bean using:
@Configuration
public class JacksonConfig {
@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.featuresToEnable(SerializationFeature.WRAP_ROOT_VALUE); // enables wrapping for root elements
return builder;
}
}
But in both cases when I run the server it returns the Pojo without the root, but the weird thing is that SWAGGER gets broken when I use that configuration.
My POJO is really simple:
@JsonRootName(value = "user")
public class User {
private long id;
private String name;
//getters and setters
}
I know there are many posts on this, but none of the solutions there seem to work for me...
Any one else have encountered this weird behaviour?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
