Class AbstractJsonHttpMessageConverter

    • Field Detail


        public static final java.nio.charset.Charset DEFAULT_CHARSET
        The default charset used by the converter.
    • Constructor Detail

      • AbstractJsonHttpMessageConverter

        public AbstractJsonHttpMessageConverter()
    • Method Detail

      • setJsonPrefix

        public void setJsonPrefix(java.lang.String jsonPrefix)
        Specify a custom prefix to use for JSON output. Default is none.
        See Also:
      • setPrefixJson

        public void setPrefixJson(boolean 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:
      • read

        public final java.lang.Object read(java.lang.reflect.Type type,
                                           java.lang.Class<?> contextClass,
                                           HttpInputMessage inputMessage)
        Description copied from interface: GenericHttpMessageConverter
        Read an object of the given type form the given input message, and returns it.
        type - the (potentially generic) type of object to return. This type must have previously been passed to the canRead method of this interface, which must have returned true.
        contextClass - a context class for the target type, for example a class in which the target type appears in a method signature (can be null)
        inputMessage - the HTTP input message to read from
        the converted object
        Throws: - in case of I/O errors
        HttpMessageNotReadableException - in case of conversion errors
      • readInternal

        protected abstract java.lang.Object readInternal(java.lang.reflect.Type resolvedType,
                                                  throws java.lang.Exception
        Template method that reads the JSON-bound object from the given Reader.
        resolvedType - the resolved generic type
        reader - the Reader to use
        the JSON-bound object
        java.lang.Exception - in case of read/parse failures
      • writeInternal

        protected abstract void writeInternal(java.lang.Object o,
                                              java.lang.reflect.Type type,
                                       throws java.lang.Exception
        Template method that writes the JSON-bound object to the given Writer.
        o - the object to write to the output message
        type - the type of object to write (may be null)
        writer - the Writer to use
        java.lang.Exception - in case of write failures