The reason for this behavior is MapperFeature DEFAULT_VIEW_INCLUSION.
From Javadoc:
The default value is enabled, which means that non-annotated properties are included in all views if there is no JsonView annotation
In Jersey, you can disable this feature with JacksonJaxbJsonProvider. This should work similarly for other JAX-RS infrastructures.
@ApplicationPath("/api")
public class MyApplication extends ResourceConfig {
public MyApplication() {
...
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
provider.setMapper(objectMapper);
register(provider);
...
}
}
source
share