use of org.springframework.http.converter.HttpMessageNotWritableException 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);
}
}
use of org.springframework.http.converter.HttpMessageNotWritableException in project pinpoint by naver.
the class MappingJsonpJackson2HttpMessageConverter method writeInternal.
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
JsonGenerator jsonGenerator = getJsonGenerator(outputMessage);
try {
String callbackParam = getRequestParam(DEFAULT_CALLBACK_PARAMETER);
if (callbackParam == null || "".equals(callbackParam)) {
callbackParam = DEFAULT_CALLBACK_PARAMETER;
}
jsonGenerator.writeRaw(callbackParam);
jsonGenerator.writeRaw(cbPrefix);
getObjectMapper().writeValue(jsonGenerator, object);
jsonGenerator.writeRaw(cbSuffix);
jsonGenerator.writeRaw(cbEnd);
jsonGenerator.flush();
} catch (JsonProcessingException e) {
throw new HttpMessageNotWritableException("Could not write JSON:" + e.getMessage(), e);
}
}
use of org.springframework.http.converter.HttpMessageNotWritableException in project java-chassis by ServiceComb.
the class TestCseHttpMessageConverter method testAll.
@Test
public void testAll() {
MockUtil.getInstance().mockReflectionUtils();
MockUtil.getInstance().mockCseClientHttpRequest();
CseHttpMessageConverter lCseHttpMessageConverter = new CseHttpMessageConverter();
lCseHttpMessageConverter.canWrite(null, null);
lCseHttpMessageConverter.getSupportedMediaTypes();
try {
lCseHttpMessageConverter.read(this.getClass(), null);
} catch (HttpMessageNotReadableException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
try {
HttpOutputMessage httpOutputMessage = Mockito.mock(CseClientHttpRequest.class);
lCseHttpMessageConverter.write(null, null, httpOutputMessage);
} catch (HttpMessageNotWritableException | IOException e) {
// TODO Auto-generated catch block
}
Assert.assertEquals(true, lCseHttpMessageConverter.canRead(null, null));
}
use of org.springframework.http.converter.HttpMessageNotWritableException in project openmrs-core by openmrs.
the class MappingJacksonHttpMessageConverter method writeInternal.
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
// https://github.com/FasterXML/jackson-databind/issues/12
if (this.objectMapper.getSerializationConfig().isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) {
jsonGenerator.useDefaultPrettyPrinter();
}
try {
if (this.jsonPrefix != null) {
jsonGenerator.writeRaw(this.jsonPrefix);
}
this.objectMapper.writeValue(jsonGenerator, object);
} catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
}
}
use of org.springframework.http.converter.HttpMessageNotWritableException in project spring-cloud-function by spring-cloud.
the class BetterGsonHttpMessageConverter 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.flush();
} catch (JsonIOException ex) {
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
}
}
Aggregations