本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializerFeature.PrettyFormat方法的典型用法代码示例。如果您正苦于以下问题:Java SerializerFeature.PrettyFormat方法的具体用法?Java SerializerFeature.PrettyFormat怎么用?Java SerializerFeature.PrettyFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.serializer.SerializerFeature
的用法示例。
在下文中一共展示了SerializerFeature.PrettyFormat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import com.alibaba.fastjson.serializer.SerializerFeature; //导入方法依赖的package包/类
/**
* 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);
}
}