/** * Overridden to provide developer writeable "JsonPath" representation * of the context. */ public final String toString() { StringBuilder sb = new StringBuilder(64); appendDesc(sb); return sb.toString(); } }
protected JsonGeneratorBase(int features) { super(); _features = features; _writeContext = JsonWriteContextImpl.createRootContext(); }
public final void writeEndObject() throws IOException, JsonGenerationException { if (!_writeContext.inObject()) { _reportError("Current context not an object but "+_writeContext.getTypeDesc()); } _writeContext = _writeContext.getParentImpl(); if (_cfgPrettyPrinter != null) { _cfgPrettyPrinter.writeEndObject(this, _writeContext.getEntryCount()); } else { doWriteEndObject(); } }
public final void writeEndArray() throws IOException, JsonGenerationException { if (!_writeContext.inArray()) { _reportError("Current context not an ARRAY but "+_writeContext.getTypeDesc()); } if (_cfgPrettyPrinter != null) { _cfgPrettyPrinter.writeEndArray(this, _writeContext.getEntryCount()); } else { doWriteEndArray(); } _writeContext = _writeContext.getParentImpl(); }
protected final void _verifyPrettyValueWrite(String typeMsg, int status) throws IOException, JsonGenerationException { // If we have a pretty printer, it knows what to do: switch (status) { case JsonWriteContextImpl.STATUS_OK_AFTER_COMMA: // array _cfgPrettyPrinter.writeArrayValueSeparator(this); break; case JsonWriteContextImpl.STATUS_OK_AFTER_COLON: _cfgPrettyPrinter.writeObjectFieldValueSeparator(this); break; case JsonWriteContextImpl.STATUS_OK_AFTER_SPACE: _cfgPrettyPrinter.writeRootValueSeparator(this); break; case JsonWriteContextImpl.STATUS_OK_AS_IS: // First entry, but of which context? if (_writeContext.inArray()) { _cfgPrettyPrinter.beforeArrayValues(this); } else if (_writeContext.inObject()) { _cfgPrettyPrinter.beforeObjectEntries(this); } break; default: _cantHappen(); break; } }
public final void writeFieldName(String name) throws IOException, JsonGenerationException { // Object is a value, need to verify it's allowed int status = _writeContext.writeFieldName(name); if (status == JsonWriteContextImpl.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); } doWriteFieldName(name, (status == JsonWriteContextImpl.STATUS_OK_AFTER_COMMA)); }
public final void writeStartArray() throws IOException, JsonGenerationException { // Array is a value, need to verify it's allowed _verifyValueWrite("start an array"); _writeContext = _writeContext.createChildArrayContext(); if (_cfgPrettyPrinter != null) { _cfgPrettyPrinter.writeStartArray(this); } else { doWriteStartArray(); } }
public final void writeStartObject() throws IOException, JsonGenerationException { _verifyValueWrite("start an object"); _writeContext = _writeContext.createChildObjectContext(); if (_cfgPrettyPrinter != null) { _cfgPrettyPrinter.writeStartObject(this); } else { doWriteStartObject(); } }