/**
* Method that JAX-RS container calls to serialize given value.
*/
public void writeTo(Object obj, //
Class<?> type, //
Type genericType, //
Annotation[] annotations, //
MediaType mediaType, //
MultivaluedMap<String, Object> httpHeaders, //
OutputStream entityStream //
) throws IOException, WebApplicationException {
FastJsonConfig fastJsonConfig = locateConfigProvider(type, mediaType);
SerializerFeature[] serializerFeatures = fastJsonConfig.getSerializerFeatures();
if (pretty) {
if (serializerFeatures == null)
serializerFeatures = new SerializerFeature[]{SerializerFeature.PrettyFormat};
else {
List<SerializerFeature> featureList = new ArrayList<SerializerFeature>(Arrays
.asList(serializerFeatures));
featureList.add(SerializerFeature.PrettyFormat);
serializerFeatures = featureList.toArray(serializerFeatures);
}
fastJsonConfig.setSerializerFeatures(serializerFeatures);
}
try {
int len = JSON.writeJSONString(entityStream, //
fastJsonConfig.getCharset(), //
obj, //
fastJsonConfig.getSerializeConfig(), //
fastJsonConfig.getSerializeFilters(), //
fastJsonConfig.getDateFormat(), //
JSON.DEFAULT_GENERATE_FEATURE, //
fastJsonConfig.getSerializerFeatures());
// // add Content-Length
// if (fastJsonConfig.isWriteContentLength()) {
// httpHeaders.add("Content-Length", String.valueOf(len));
// }
entityStream.flush();
} catch (JSONException ex) {
throw new WebApplicationException("Could not write JSON: " + ex.getMessage(), ex);
}
}
FastJsonProvider.java 文件源码
java
阅读 42
收藏 0
点赞 0
评论 0
项目:GitHub
作者:
评论列表
文章目录