Search in sources :

Example 6 with JsonIOException

use of com.google.gson.JsonIOException in project spring-framework by spring-projects.

the class GsonHttpMessageConverter method writeInternal.

@Override
protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    Charset charset = getCharset(outputMessage.getHeaders());
    OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset);
    try {
        if (this.jsonPrefix != null) {
            writer.append(this.jsonPrefix);
        }
        if (type != null) {
            this.gson.toJson(o, type, writer);
        } else {
            this.gson.toJson(o, writer);
        }
        writer.close();
    } catch (JsonIOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
Also used : HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) JsonIOException(com.google.gson.JsonIOException) Charset(java.nio.charset.Charset) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

JsonIOException (com.google.gson.JsonIOException)6 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 Type (java.lang.reflect.Type)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 GitClientApplication (com.gitblit.models.GitClientApplication)1 JsonParseException (com.google.gson.JsonParseException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1