本文整理汇总了Java中com.fasterxml.jackson.core.JsonGenerator.writeRaw方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeRaw方法的具体用法?Java JsonGenerator.writeRaw怎么用?Java JsonGenerator.writeRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeRaw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSurrogatesWithRaw
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
public void testSurrogatesWithRaw() throws Exception
{
final String VALUE = quote("\ud83d\ude0c");
ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonGenerator g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
g.writeStartArray();
g.writeRaw(VALUE);
g.writeEndArray();
g.close();
final byte[] JSON = out.toByteArray();
JsonParser jp = JSON_F.createParser(ObjectReadContext.empty(), JSON);
assertToken(JsonToken.START_ARRAY, jp.nextToken());
assertToken(JsonToken.VALUE_STRING, jp.nextToken());
String str = jp.getText();
assertEquals(2, str.length());
assertEquals((char) 0xD83D, str.charAt(0));
assertEquals((char) 0xDE0C, str.charAt(1));
assertToken(JsonToken.END_ARRAY, jp.nextToken());
jp.close();
}
示例2: OutputStreamDemo
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
public static void OutputStreamDemo() throws IOException {
String out = "";
JsonFactory f = new JsonFactory();
FileOutputStream fos = new FileOutputStream(new File("user.out.json"));
JsonGenerator g = f.createGenerator(fos);
g.writeStartObject();
g.writeObjectFieldStart("name");
g.writeStringField("first", "BorLion");
g.writeStringField("last", "Zhu");
g.writeEndObject(); // for field 'name'
g.writeStringField("gender", "MALE");
g.writeBooleanField("verified", true);
g.writeBinaryField("userImage", "Rm9vYmFyIQ==".getBytes());
g.writeEndObject();
g.writeRaw('\n');
g.close();
}
示例3: writeValue
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeValue(Any message, JsonGenerator gen) throws IOException {
if (message.equals(Any.getDefaultInstance())) {
// Note: empty Any is not indented the same way as an empty message, this is likely an
// upstream bug.
gen.writeRaw(": {}");
return;
}
gen.writeStartObject();
String typeUrl = message.getTypeUrl();
TypeSpecificMarshaller<?> serializer = marshallerRegistry.findByTypeUrl(typeUrl);
gen.writeFieldName("@type");
gen.writeString(typeUrl);
if (serializer instanceof WellKnownTypeMarshaller) {
gen.writeFieldName("value");
serializer.writeValue(message.getValue(), gen);
} else {
serializer.doWrite(message.getValue(), gen);
}
gen.writeEndObject();
}
示例4: writeEndObject
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeEndObject(JsonGenerator g, int nrOfEntries) throws IOException {
if (!this._objectIndenter.isInline()) {
--this._nesting;
}
if (nrOfEntries > 0) {
this._objectIndenter.writeIndentation(g, this._nesting);
} else {
// lets disable the space in empty objects
//g.writeRaw(' ');
}
g.writeRaw('}');
}
示例5: writeRootValueSeparator
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeRootValueSeparator(JsonGenerator g) throws IOException
{
if (_rootValueSeparator != null) {
g.writeRaw(_rootValueSeparator);
}
}
示例6: writeObjectFieldValueSeparator
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeObjectFieldValueSeparator(JsonGenerator jg)
throws IOException, JsonGenerationException {
/**
* Custom object separator (Default is " : ") to make it easier to compare state dumps with other
* ethereum client implementations
*/
jg.writeRaw(": ");
}
示例7: writeInternal
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
// The following has been deprecated as late as Jackson 2.2 (April 2013);
// preserved for the time being, for Jackson 2.0/2.1 compatibility.
@SuppressWarnings("deprecation")
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.isEnabled(SerializationFeature.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);
}
}
示例8: writeEndObject
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeEndObject(JsonGenerator jg, int nrOfEntries) throws IOException {
if (!_objectIndenter.isInline()) {
--_nesting;
}
_objectIndenter.writeIndentation(jg, _nesting);
jg.writeRaw('}');
}
示例9: writeIndentation
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
public void writeIndentation(JsonGenerator jg, int level) throws IOException, JsonGenerationException {
jg.writeRaw(SYSTEM_LINE_SEPARATOR);
if (level > 0) {
level += level; // 2 spaces per level
while (level > SPACE_COUNT) { // should never happen but...
jg.writeRaw(SPACES, 0, SPACE_COUNT);
level -= SPACES.length;
}
jg.writeRaw(SPACES, 0, level);
}
}
示例10: writeStartObject
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeStartObject(JsonGenerator g) throws IOException
{
g.writeRaw('{');
}
示例11: writeEndObject
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeEndObject(JsonGenerator g, int nrOfEntries) throws IOException
{
g.writeRaw('}');
}
示例12: writeStartArray
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeStartArray(JsonGenerator g) throws IOException
{
g.writeRaw('[');
}
示例13: writeEndArray
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeEndArray(JsonGenerator g, int nrOfValues) throws IOException
{
g.writeRaw(']');
}
示例14: writeObjectFieldValueSeparator
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
jg.writeRaw(": ");
}
示例15: writeEndArray
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void writeEndArray(JsonGenerator gen, int nrOfValues) throws IOException {
gen.writeRaw(']');
}