Spring provides support for the Jackson JSON library.
MVC JSON views based on the Jackson library
MappingJackson2JsonView
uses the Jackson library's ObjectMapper
to display the contents of
the response in JSON format. By default, all Map model contents (except for framework-specific classes) are encoded
in JSON format. In cases where Map content needs to be filtered, you can specify a specific set of model attributes
to encode using the modelKeys
property. You can also use the
extractValueFromSingleKeyModel
property so that the value in single-key models is extracted and
serialized directly rather than as a Model Attribute Map
You can customize the JSON mapping to your liking using the annotations provided by Jackson. If you need additional
control, you can implement a custom ObjectMapper
via the ObjectMapper
property for cases
where you need to specify custom JSON serializers and deserializers for specific types.
XML representations based on the Jackson library
MappingJackson2XmlView
uses XmlMapper Jackson library XML extensions for
displaying the response content as XML. If a model contains multiple records, you must explicitly set the object to
be serialized using the modelKey
bean property. If the model contains one record, it is serialized
automatically.
You can customize the XML rendering as you wish using JAXB or the annotations provided by Jackson. If you need
additional control, you can implement a custom XmlMapper
through the ObjectMapper
property
in cases where the custom XML needs to provide serializers and deserializers for certain types.
GO TO FULL VERSION