當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonGenerator.writeRaw方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:MappingJacksonHttpMessageConverter.java

示例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);
	}
}
 
開發者ID:bestarandyan,項目名稱:ShoppingMall,代碼行數:18,代碼來源:MappingJacksonHttpMessageConverter.java

示例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());
}
 
開發者ID:Appverse,項目名稱:appverse-server,代碼行數:19,代碼來源:CustomMappingJacksonHttpMessageConverter.java

示例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);
    }
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:31,代碼來源:JsonTransformer.java


注:本文中的org.codehaus.jackson.JsonGenerator.writeRaw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。