com.fasterxml.jackson.core.JsonStreamContext#inRoot ( )源码实例Demo

下面列出了com.fasterxml.jackson.core.JsonStreamContext#inRoot ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: crate   文件: JsonXContentGenerator.java
@Override
public void close() throws IOException {
    if (generator.isClosed()) {
        return;
    }
    JsonStreamContext context = generator.getOutputContext();
    if ((context != null) && (context.inRoot() == false)) {
        throw new IOException("Unclosed object or array found");
    }
    if (writeLineFeedAtEnd) {
        flush();
        // Bypass generator to always write the line feed
        getLowLevelGenerator().writeRaw(LF);
    }
    generator.close();
}
 
源代码2 项目: Elasticsearch   文件: JsonXContentGenerator.java
protected boolean inRoot() {
    if (isFiltered()) {
        JsonStreamContext context = filter.getFilterContext();
        return ((context != null) && (context.inRoot() && context.getCurrentName() == null));
    }
    return false;
}
 
源代码3 项目: ameba   文件: CommonBeanSerializer.java
/**
 * only first call return FetchPath
 * <p>
 * and then call is bean sub-path (property)
 *
 * @return fetch path or null
 */
private FetchPath getPathProperties(JsonGenerator jsonGenerator) {
    FetchPath fetchPath = EbeanUtils.getRequestFetchPath();
    if (fetchPath != null) {
        JsonStreamContext context = jsonGenerator.getOutputContext();
        JsonStreamContext parent = context.getParent();
        if (parent == null) {
            return fetchPath;
        }
        StringBuilder path = new StringBuilder();
        while (parent != null && !parent.inRoot()) {
            if (parent != context.getParent()) {
                path.insert(0, '.');
            }
            path.insert(0, parent.getCurrentName());
            parent = parent.getParent();
        }
        String fp = path.toString();
        PathProperties fetch = new PathProperties();
        EbeanPathProps src = (EbeanPathProps) fetchPath;
        String cp = fp + ".";
        for (BeanPathProperties.Props prop : src.getPathProps()) {
            String pp = prop.getPath();
            if (pp != null) {
                if (pp.equals(fp)) {
                    addToFetchPath(fetch, null, prop);
                } else if (pp.startsWith(cp)) {
                    addToFetchPath(fetch, pp.substring(cp.length()), prop);
                }
            }
        }

        return fetch;
    }
    return null;
}
 
public void serializeFromError(JsonStreamContext ctxt, @Nullable Exception error, Object value, JsonGenerator jgen, SerializerProvider configurableSerializerProvider) throws IOException {
    if (log.isDebugEnabled())
        log.debug("Recovering from json serialization error, serializing "+value+": "+error);

    if (BidiSerialization.isStrictSerialization())
        throw new JsonMappingException("Cannot serialize "
            + (ctxt!=null && !ctxt.inRoot() ? "object containing " : "")
            + value.getClass().getName()+" when strict serialization requested");

    if (WARNED_CLASSES.add(value.getClass().getCanonicalName())) {
        log.warn("Standard serialization not possible for "+value.getClass()+" ("+value+")", error);
    }
    JsonStreamContext newCtxt = jgen.getOutputContext();

    // very odd, but flush seems necessary when working with large objects; presumably a buffer which is allowed to clear itself?
    // without this, when serializing the large (1.5M) Server json object from BrooklynJacksonSerializerTest creates invalid json,
    // containing:  "foo":false,"{"error":true,...
    jgen.flush();

    boolean createObject = !newCtxt.inObject() || newCtxt.getCurrentName()!=null;
    if (createObject) {
        jgen.writeStartObject();
    }

    if (allowEmpty(value.getClass())) {
        // write nothing
    } else {

        jgen.writeFieldName("error");
        jgen.writeBoolean(true);

        jgen.writeFieldName("errorType");
        jgen.writeString(NotSerializableException.class.getCanonicalName());

        jgen.writeFieldName("type");
        jgen.writeString(value.getClass().getCanonicalName());

        jgen.writeFieldName("toString");
        jgen.writeString(value.toString());

        if (error!=null) {
            jgen.writeFieldName("causedByError");
            jgen.writeString(error.toString());
        }

    }

    if (createObject) {
        jgen.writeEndObject();
    }

    while (newCtxt!=null && !newCtxt.equals(ctxt)) {
        if (jgen.getOutputContext().inArray()) { jgen.writeEndArray(); continue; }
        if (jgen.getOutputContext().inObject()) { jgen.writeEndObject(); continue; }
        break;
    }

}
 
源代码5 项目: crate   文件: JsonXContentGenerator.java
private boolean inRoot() {
    JsonStreamContext context = generator.getOutputContext();
    return ((context != null) && (context.inRoot() && context.getCurrentName() == null));
}