Example usage for com.fasterxml.jackson.core.json JsonWriteContext STATUS_OK_AFTER_COMMA

List of usage examples for com.fasterxml.jackson.core.json JsonWriteContext STATUS_OK_AFTER_COMMA

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.json JsonWriteContext STATUS_OK_AFTER_COMMA.

Prototype

int STATUS_OK_AFTER_COMMA

To view the source code for com.fasterxml.jackson.core.json JsonWriteContext STATUS_OK_AFTER_COMMA.

Click Source Link

Usage

From source file:org.brutusin.json.impl.serializers.JsonNodeSerializer.java

@Override
public void serialize(JsonNode value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    JsonWriteContext ctx = (JsonWriteContext) gen.getOutputContext();

    int status = ctx.writeValue();
    switch (status) {
    case JsonWriteContext.STATUS_OK_AFTER_COMMA:
        gen.writeRaw(',');
        break;//from   w  w w  .j  a  v a2 s . c om
    case JsonWriteContext.STATUS_OK_AFTER_COLON:
        gen.writeRaw(':');
        break;
    case JsonWriteContext.STATUS_OK_AFTER_SPACE:
        gen.writeRaw(' ');
        break;
    }
    ;
    if (value == null) {
        gen.writeRaw("null");
    } else {
        gen.writeRaw(value.toString());
    }
}

From source file:org.brutusin.json.impl.serializers.InputStreamSerializer.java

@Override
public void serialize(InputStream value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    JsonWriteContext ctx = (JsonWriteContext) gen.getOutputContext();
    int status = ctx.writeValue();
    switch (status) {
    case JsonWriteContext.STATUS_OK_AFTER_COMMA:
        gen.writeRaw(',');
        break;//from ww  w  .  j  a v a2  s. c  o  m
    case JsonWriteContext.STATUS_OK_AFTER_COLON:
        gen.writeRaw(':');
        break;
    case JsonWriteContext.STATUS_OK_AFTER_SPACE:
        gen.writeRaw(' ');
        break;
    }
    ;
    if (value == null) {
        gen.writeRaw("null");
    } else {
        SerializationContext sCtx = SerializationContext.getCurrentContext();
        if (sCtx == null) {
            sCtx = new SerializationContext();
            SerializationContext.setCurrentContext(sCtx);
        }
        gen.writeRaw("\"" + sCtx.addStream(value) + "\"");
    }
}

From source file:com.bazaarvoice.jackson.rison.RisonGenerator.java

@Override
public void writeFieldName(String name) throws IOException, JsonGenerationException {
    int status = _writeContext.writeFieldName(name);
    if (status == JsonWriteContext.STATUS_EXPECT_VALUE) {
        _reportError("Can not write a field name, expecting a value");
    }/*from   w  w  w. j  av  a 2s  .  c o  m*/
    _writeFieldName(name, (status == JsonWriteContext.STATUS_OK_AFTER_COMMA));
}

From source file:com.bazaarvoice.jackson.rison.RisonGenerator.java

@Override
public void writeFieldName(SerializableString name) throws IOException, JsonGenerationException {
    // Object is a value, need to verify it's allowed
    int status = _writeContext.writeFieldName(name.getValue());
    if (status == JsonWriteContext.STATUS_EXPECT_VALUE) {
        _reportError("Can not write a field name, expecting a value");
    }//from  w  ww  .  j  a v  a  2s  . co m
    _writeFieldName(name, (status == JsonWriteContext.STATUS_OK_AFTER_COMMA));
}

From source file:com.bazaarvoice.jackson.rison.RisonGenerator.java

@Override
protected final void _verifyValueWrite(String typeMsg) throws IOException, JsonGenerationException {
    int status = _writeContext.writeValue();
    if (status == JsonWriteContext.STATUS_EXPECT_NAME) {
        _reportError("Can not " + typeMsg + ", expecting field name");
    }//from  w ww . j  a  v  a 2 s .co  m
    char c;
    switch (status) {
    case JsonWriteContext.STATUS_OK_AFTER_COMMA:
        c = ',';
        break;
    case JsonWriteContext.STATUS_OK_AFTER_COLON:
        c = ':';
        break;
    case JsonWriteContext.STATUS_OK_AFTER_SPACE:
        if (_rootValueSeparator != null) {
            _writeRaw(_rootValueSeparator.getValue());
        }
        return;
    case JsonWriteContext.STATUS_OK_AS_IS:
    default:
        return;
    }
    if (_outputTail >= _outputEnd) {
        _flushBuffer();
    }
    _outputBuffer[_outputTail++] = c;
}