Class JacksonJsonHttpMessageConverter

All Implemented Interfaces:
HttpMessageConverter<Object>, smartHttpMessageConverter<Object>

public class JacksonJsonHttpMessageConverter extends AbstractJacksonHttpMessageConverter<tools.jackson.databind.json.JsonMapper>
Implementation of HttpMessageConverter that can read and write JsON using Jackson 3.x's JsonMapper.

This converter can be used to bind to typed beans, or untyped HashMap instances.

By default, this converter supports application/json and application/*+json with UTF-8 character set. This can be overridden by setting the supportedMediaTypes property.

The following hints entries are supported:

  • A JsON view with a "com.fasterxml.jackson.annotation.JsonView" key and the class name of the JsON view as value.
  • A filter provider with a "tools.jackson.databind.ser.FilterProvider" key and the filter provider class name as value.
since:
7.0
Author:
sebastien Deleuze
  • Constructor Details

    • JacksonJsonHttpMessageConverter

      public&nbsp;JacksonJsonHttpMessageConverter()
      Construct a new instance with a JsonMapper customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader) and ProblemDetailJacksonMixin.
    • JacksonJsonHttpMessageConverter

      public&nbsp;JacksonJsonHttpMessageConverter(tools.jackson.databind.json.JsonMapper.Builder&nbsp;builder)
      Construct a new instance with the provided JsonMapper.Builder customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader) and ProblemDetailJacksonMixin.
      see Also:
      • JsonMapper.builder()
    • JacksonJsonHttpMessageConverter

      public&nbsp;JacksonJsonHttpMessageConverter(tools.jackson.databind.json.JsonMapper&nbsp;mapper)
      Construct a new instance with the provided JsonMapper.
      see Also:
      • JsonMapper.builder()
  • Method Details

    • setJsonPrefix

      public&nbsp;void&nbsp;setJsonPrefix(string&nbsp;jsonPrefix)
      specify a custom prefix to use for this view's JsON output. Default is none.
      see Also:
    • setPrefixJson

      public&nbsp;void&nbsp;setPrefixJson(boolean&nbsp;prefixJson)
      Indicate whether the JsON output by this view should be prefixed with ")]}', ". Default is false.

      Prefixing the JsON string in this manner is used to help prevent JsON Hijacking. The prefix renders the string syntactically invalid as a script so that it cannot be hijacked. This prefix should be stripped before parsing the string as JsON.

      see Also:
    • getMediaTypesForProblemDetail

      protected&nbsp;List<MediaType>&nbsp;getMediaTypesForProblemDetail()
      Description copied from class:&nbsp;AbstractJacksonHttpMessageConverter
      Return the supported media type(s) for ProblemDetail. By default, an empty list, unless overridden in subclasses.
      Overrides:
      getMediaTypesForProblemDetail&nbsp;in class&nbsp;AbstractJacksonHttpMessageConverter<tools.jackson.databind.json.JsonMapper>
    • writePrefix

      protected&nbsp;void&nbsp;writePrefix(tools.jackson.core.JsonGenerator&nbsp;generator, Object&nbsp;object)
      Description copied from class:&nbsp;AbstractJacksonHttpMessageConverter
      Write a prefix before the main content.
      Overrides:
      writePrefix&nbsp;in class&nbsp;AbstractJacksonHttpMessageConverter<tools.jackson.databind.json.JsonMapper>
      Parameters:
      generator - the generator to use for writing content.
      object - the object to write to the output message