public class

StringHttpMessageConverter

extends AbstractHttpMessageConverter<T>
java.lang.Object
   ↳ org.springframework.http.converter.AbstractHttpMessageConverter<T>
     ↳ org.springframework.http.converter.StringHttpMessageConverter

Class Overview

Implementation of HttpMessageConverter that can read and write strings.

By default, this converter supports all media types (*/*), and writes with a Content-Type of text/plain. This can be overridden by setting the supportedMediaTypes property.

Summary

Fields
public static final Charset DEFAULT_CHARSET
[Expand]
Inherited Fields
From class org.springframework.http.converter.AbstractHttpMessageConverter
Public Constructors
StringHttpMessageConverter()
Public Methods
void setWriteAcceptCharset(boolean writeAcceptCharset)
Indicates whether the Accept-Charset should be written to any outgoing request.
boolean supports(Class<?> clazz)
Indicates whether the given class is supported by this converter.
Protected Methods
List<Charset> getAcceptedCharsets()
Return the list of supported Charset.
Long getContentLength(String s, MediaType contentType)
Returns the content length for the given type.
String readInternal(Class clazz, HttpInputMessage inputMessage)
Abstract template method that reads the actualy object.
void writeInternal(String s, HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.
[Expand]
Inherited Methods
From class org.springframework.http.converter.AbstractHttpMessageConverter
From class java.lang.Object
From interface org.springframework.http.converter.HttpMessageConverter

Fields

public static final Charset DEFAULT_CHARSET

Public Constructors

public StringHttpMessageConverter ()

Public Methods

public void setWriteAcceptCharset (boolean writeAcceptCharset)

Indicates whether the Accept-Charset should be written to any outgoing request.

Default is true.

public boolean supports (Class<?> clazz)

Indicates whether the given class is supported by this converter.

Parameters
clazz the class to test for support
Returns
  • true if supported; false otherwise

Protected Methods

protected List<Charset> getAcceptedCharsets ()

Return the list of supported Charset.

By default, returns availableCharsets(). Can be overridden in subclasses.

Returns
  • the list of accepted charsets

protected Long getContentLength (String s, MediaType contentType)

Returns the content length for the given type.

By default, this returns null, meaning that the content length is unknown. Can be overridden in subclasses.

Parameters
s the type to return the content length for
Returns
  • the content length, or null if not known

protected String readInternal (Class clazz, HttpInputMessage inputMessage)

Abstract template method that reads the actualy object. Invoked from read(Class, HttpInputMessage).

Parameters
clazz the type of object to return
inputMessage the HTTP input message to read from
Returns
  • the converted object
Throws
IOException

protected void writeInternal (String s, HttpOutputMessage outputMessage)

Abstract template method that writes the actual body. Invoked from write(T, MediaType, HttpOutputMessage).

Parameters
s the object to write to the output message
outputMessage the message to write to
Throws
IOException