|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 7.0.1! |
Jackson
Spring offers support for the Jackson JSON library.
Jackson-based JSON MVC Views
The JacksonJsonView uses the Jackson library’s JsonMapper to render the response
content as JSON. By default, the entire contents of the model map (with the exception of
framework-specific classes) are encoded as JSON. For cases where the contents of the
map need to be filtered, you can specify a specific set of model attributes to encode
by using the modelKeys property. You can also use the extractValueFromSingleKeyModel
property to have the value in single-key models extracted and serialized directly rather
than as a map of model attributes.
You can customize JSON mapping as needed by using Jackson’s provided annotations. When
you need further control, you can inject a custom JsonMapper through the JsonMapper
or JsonMapper.Builder constructor parameters, for cases where you need to provide
custom JSON serializers and deserializers for specific types.
Jackson-based XML Views
JacksonXmlView uses the
Jackson XML extension’s XmlMapper
to render the response content as XML. If the model contains multiple entries, you should
explicitly set the object to be serialized by using the modelKey bean property. If the
model contains a single entry, it is serialized automatically.
You can customize XML mapping as needed by using JAXB or Jackson’s provided
annotations. When you need further control, you can inject a custom XmlMapper
created via XmlMapper.Builder for cases where custom XML you need to provide
serializers and deserializers for specific types.