JsonView class

Puts a property into one or more views, so the same class can be written with fewer or more properties depending on who reads it.

Use it to serve a public and an internal form of a model without two classes. A view is any class; a view class that extends another includes it. mapper.writerWithView(Public) writes (and readerWithView reads) only the properties of that view or of a view it extends; properties without a view only when defaultViewInclusion is on (off by default, like Jackson 3 and Spring Boot). On a class it is the default view of its properties. The view classes named here are introspected, which is how the mapper knows which extends which.

// Public callers get the name; internal ones also the email.
class Public {}
class Internal extends Public {}

@JsonView([Public]) final String name;
@JsonView([Internal]) final String email;

mapper.writerWithView(Public).writeValueAsString(user); // {"name": ...}

Spring (Java):

@JsonView(Views.Public.class) String name;
mapper.writerWithView(Views.Public.class).writeValueAsString(user);

Constructors

JsonView(List<Type> value)
Puts the property into the views value.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → List<Type>
The view classes the property belongs to.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited