Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeRaw()

The following examples show how to use com.fasterxml.jackson.core.JsonGenerator#writeRaw() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringUnicodeSerializer.java    From springboot-seed with MIT License 5 votes vote down vote up
private void writeUnicodeEscape(JsonGenerator gen, char c) throws IOException {
    gen.writeRaw('\\');
    gen.writeRaw('u');
    gen.writeRaw(HEX_CHARS[(c >> 12) & 0xF]);
    gen.writeRaw(HEX_CHARS[(c >> 8) & 0xF]);
    gen.writeRaw(HEX_CHARS[(c >> 4) & 0xF]);
    gen.writeRaw(HEX_CHARS[c & 0xF]);
}
 
Example 2
Source File: JsonCodec.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
private static void writeUnicodeEscape(JsonGenerator gen, char c) throws IOException {
  gen.writeRaw('\\');
  gen.writeRaw('u');
  gen.writeRaw(HEX_CHARS[(c >> 12) & 0xF]);
  gen.writeRaw(HEX_CHARS[(c >> 8) & 0xF]);
  gen.writeRaw(HEX_CHARS[(c >> 4) & 0xF]);
  gen.writeRaw(HEX_CHARS[c & 0xF]);
}
 
Example 3
Source File: MappingJacksonHttpMessageConverter.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {
	JsonEncoding encoding = getEncoding(outputMessage.getHeaders().getContentType());
	JsonGenerator jsonGenerator =
			objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
	if (prefixJson) {
		jsonGenerator.writeRaw("{} && ");
	}
	objectMapper.writeValue(jsonGenerator, o);
}
 
Example 4
Source File: NpmJsonPrettyPrinter.java    From updatebot with Apache License 2.0 5 votes vote down vote up
@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('}');
}
 
Example 5
Source File: StandardJsonPrettyPrinter.java    From typescript-generator with MIT License 5 votes vote down vote up
@Override
public void writeEndObject(JsonGenerator g, int nrOfEntries) throws IOException {
    if (!_objectIndenter.isInline()) {
        --_nesting;
    }
    if (nrOfEntries > 0) {
        _objectIndenter.writeIndentation(g, _nesting);
    }
    g.writeRaw('}');
}
 
Example 6
Source File: DefaultIndenter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeIndentation(JsonGenerator jg, int level) throws IOException
{
    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);
    }
}
 
Example 7
Source File: Utils.java    From ask-sdk-frameworks-java with Apache License 2.0 5 votes vote down vote up
@Override
public void writeIndentation(JsonGenerator jsonGenerator, int i) throws IOException {
    jsonGenerator.writeRaw('\n');
    for (int j = 0; j < i; j++) {
        jsonGenerator.writeRaw("  ");
    }
}
 
Example 8
Source File: StandardJsonPrettyPrinter.java    From typescript-generator with MIT License 5 votes vote down vote up
@Override
public void writeEndArray(JsonGenerator g, int nrOfValues) throws IOException {
    if (!_arrayIndenter.isInline()) {
        --_nesting;
    }
    if (nrOfValues > 0) {
        _arrayIndenter.writeIndentation(g, _nesting);
    }
    g.writeRaw(']');
}
 
Example 9
Source File: JsonUtils.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
/** See {@link DefaultPrettyPrinter.Lf2SpacesIndenter#writeIndentation(JsonGenerator, int)} */
@Override
public void writeIndentation(JsonGenerator jg, int level) throws IOException {
    jg.writeRaw(LINE_FEED);
    if (level > 0) {
        level += level;
        while (level > SPACE_COUNT) {
            jg.writeRaw(SPACES, 0, SPACE_COUNT);
            level -= SPACES.length;
        }
        jg.writeRaw(SPACES, 0, level);
    }
}
 
Example 10
Source File: MappingJacksonRPC2HttpMessageConverter.java    From jsonrpc4j with MIT License 5 votes vote down vote up
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	final JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
	final JsonGenerator jsonGenerator = this.objectMapper.getFactory().createGenerator(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);
	}
}
 
Example 11
Source File: JsonContentHandlerJacksonWrapper.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void maybeOutputNlOrBlank(JsonGenerator jg) throws IOException {
  if (doNl) {
    maybeOutputNl(jg);  // resets doNl
  } else {
    jg.writeRaw(' ');
  }
}
 
Example 12
Source File: DefaultIndenter.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeIndentation(JsonGenerator jg, int level) throws IOException
{
    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);
    }
}
 
Example 13
Source File: MinimalPrettyPrinter.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void writeStartArray(JsonGenerator jg)
    throws IOException, JsonGenerationException
{
    jg.writeRaw('[');
}
 
Example 14
Source File: MinimalPrettyPrinter.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void writeEndObject(JsonGenerator jg, int nrOfEntries)
    throws IOException, JsonGenerationException
{
    jg.writeRaw('}');
}
 
Example 15
Source File: LocalDevice.java    From daq with Apache License 2.0 4 votes vote down vote up
@Override
public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
  jg.writeRaw(": ");
}
 
Example 16
Source File: ObjectMappers.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@Override
public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
    jg.writeRaw(": ");
}
 
Example 17
Source File: MappingJackson2JsonView.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void writePrefix(JsonGenerator generator, Object object) throws IOException {
	if (this.jsonPrefix != null) {
		generator.writeRaw(this.jsonPrefix);
	}
}
 
Example 18
Source File: EndpointsPrettyPrinter.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@Override
public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
  jg.writeRaw(": ");
}
 
Example 19
Source File: StandardJsonPrettyPrinter.java    From typescript-generator with MIT License 4 votes vote down vote up
@Override
public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
    jg.writeRaw(": ");
}
 
Example 20
Source File: MappingJackson2JsonView.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void writePrefix(JsonGenerator generator, Object object) throws IOException {
	if (this.jsonPrefix != null) {
		generator.writeRaw(this.jsonPrefix);
	}
}