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

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

Introduction

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

Prototype

public final int writeValue() 

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;//  ww w.j a  v a 2s .co  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 {
        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 av  a 2s  . 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 {
        SerializationContext sCtx = SerializationContext.getCurrentContext();
        if (sCtx == null) {
            sCtx = new SerializationContext();
            SerializationContext.setCurrentContext(sCtx);
        }
        gen.writeRaw("\"" + sCtx.addStream(value) + "\"");
    }
}