本文整理汇总了Java中org.codehaus.jackson.JsonGenerator.writeRaw方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeRaw方法的具体用法?Java JsonGenerator.writeRaw怎么用?Java JsonGenerator.writeRaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeRaw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeInternal
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@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);
// A workaround for JsonGenerators not applying serialization features
// 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);
}
}
示例2: writeInternal
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@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);
try {
if (this.prefixJson) {
jsonGenerator.writeRaw("{} && ");
}
this.objectMapper.writeValue(jsonGenerator, object);
}
catch (IOException ex) {
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
}
}
示例3: writeInternal
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
JsonEncoding encoding = getEncoding(outputMessage.getHeaders()
.getContentType());
JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory()
.createJsonGenerator(outputMessage.getBody(), encoding);
if (this.prefixJson) {
jsonGenerator.writeRaw("{} && ");
}
this.objectMapper.writeValue(jsonGenerator, o);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonGenerator baosjsonGenerator = this.objectMapper.getJsonFactory()
.createJsonGenerator(baos, encoding);
this.objectMapper.writeValue(baosjsonGenerator, o);
logger.debug("Middleware returns " + o.getClass().getName() + " "
+ baos.toString());
}
示例4: writeIndentation
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeIndentation(JsonGenerator jg, int level)
{
try
{
if (!compact)
{
jg.writeRaw(eol);
if (level > 0)
{ // should we err on negative values (as there's some flaw?)
level *= charsPerLevel;
while (level > indents.length)
{ // unlike to happen but just in case
jg.writeRaw(indents, 0, indents.length);
level -= indents.length;
}
jg.writeRaw(indents, 0, level);
}
}
else
{
jg.writeRaw(space);
}
}
catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
}