I annotated class User with @JsonView and when it returned I see all fields even than that not contains in view class. Here is my class
@Entity
@Table(name =
I've spend a some debugging time with the same issue. Results are:
all fields are included by default if you do not change this behavior (see BeanSerializerFactory.processViews
). To change default do:
ObjectMapper mapper = new ObjectMapper();
mapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
fields, marked by @JsonView
omitted in result if controller method annotated with OTHER @JsonView
(see FilteredBeanPropertyWriter.serializeAsField
)
So for your use-case do not change default settings, annotate Long userID
by @JsonView
and getUser
by any other (not the same) View.
Code com\fasterxml\jackson\core\jackson-databind\2.8.4\jackson-databind-2.8.4-sources.jar!\com\fasterxml\jackson\databind\MapperFeature.java
* Feature is enabled by default.
*/
DEFAULT_VIEW_INCLUSION(true)
is contradicted of blog https://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring, so I have to look at code closer.