Example usage for com.fasterxml.jackson.core JsonStreamContext inObject

List of usage examples for com.fasterxml.jackson.core JsonStreamContext inObject

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonStreamContext inObject.

Prototype

public final boolean inObject() 

Source Link

Document

Method that returns true if this context is an Object context; that is, content is being read from or written to a Json Object.

Usage

From source file:org.culturegraph.mf.stream.converter.JsonEncoder.java

private void endGroup() {
    try {/* w  w w.  java 2 s .  c o  m*/
        final JsonStreamContext ctx = jsonGenerator.getOutputContext();
        if (ctx.inObject()) {
            jsonGenerator.writeEndObject();
        } else if (ctx.inArray()) {
            jsonGenerator.writeEndArray();
        }
    } catch (final JsonGenerationException e) {
        throw new MetafactureException(e);
    } catch (final IOException e) {
        throw new MetafactureException(e);
    }
}

From source file:org.culturegraph.mf.stream.converter.JsonEncoder.java

@Override
public void literal(final String name, final String value) {
    try {/*from  w  ww  . ja va  2s  . co  m*/
        final JsonStreamContext ctx = jsonGenerator.getOutputContext();
        if (ctx.inObject()) {
            jsonGenerator.writeFieldName(name);
        }
        if (value == null) {
            jsonGenerator.writeNull();
        } else {
            jsonGenerator.writeString(value);
        }
    } catch (final JsonGenerationException e) {
        throw new MetafactureException(e);
    } catch (final IOException e) {
        throw new MetafactureException(e);
    }
}

From source file:org.culturegraph.mf.stream.converter.JsonEncoder.java

private void startGroup(final String name) {
    try {/*from ww w.  j av a  2s  .c o  m*/
        final JsonStreamContext ctx = jsonGenerator.getOutputContext();
        if (name.endsWith(ARRAY_MARKER)) {
            if (ctx.inObject()) {
                jsonGenerator.writeFieldName(name.substring(0, name.length() - ARRAY_MARKER.length()));
            }
            jsonGenerator.writeStartArray();
        } else {
            if (ctx.inObject()) {
                jsonGenerator.writeFieldName(name);
            }
            jsonGenerator.writeStartObject();
        }
    } catch (final JsonGenerationException e) {
        throw new MetafactureException(e);
    } catch (final IOException e) {
        throw new MetafactureException(e);
    }
}

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

@Override
public void close() throws IOException {
    super.close();

    /* 05-Dec-2008, tatu: To add [JACKSON-27], need to close open
     *   scopes.//from  w  w  w .  jav a2s  . c o m
     */
    // First: let's see that we still have buffers...
    if (_outputBuffer != null && isEnabled(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT)) {
        while (true) {
            JsonStreamContext ctxt = getOutputContext();
            if (ctxt.inArray()) {
                writeEndArray();
            } else if (ctxt.inObject()) {
                writeEndObject();
            } else {
                break;
            }
        }
    }
    _flushBuffer();

    /* 25-Nov-2008, tatus: As per [JACKSON-16] we are not to call close()
     *   on the underlying Reader, unless we "own" it, or auto-closing
     *   feature is enabled.
     *   One downside: when using UTF8Writer, underlying buffer(s)
     *   may not be properly recycled if we don't close the writer.
     */
    if (_writer != null) {
        if (_ioContext.isResourceManaged() || isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)) {
            _writer.close();
        } else if (isEnabled(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)) {
            // If we can't close it, we should at least flush
            _writer.flush();
        }
    }
    // Internal buffer(s) generator has can now be released as well
    _releaseBuffers();
}