protected void writeComma() { if (!currentContext.first && currentContext.scope != Scope.IN_FIELD) { writeChar(','); } currentContext.first = false; }
protected void writeColon() { writeChar(':'); }
void writeEscapedString(String string) { writeChar('"'); int len = string.length(); for(int i = 0; i < len; i++) { case '"': case '\\': writeChar('\\'); writeChar(c); break; case '\b': writeChar('\\'); writeChar('b'); break; case '\f': writeChar('\\'); writeChar('f'); break; case '\n': writeChar('\\'); writeChar('n'); break; case '\r': writeChar('\\'); writeChar('r'); break; case '\t': writeChar('\\'); writeChar('t'); break; default: writeChar('"');
@Override public JsonGenerator writeEnd() { if (currentContext.scope == Scope.IN_NONE) { throw new JsonGenerationException("writeEnd() cannot be called in no context"); } writeChar(currentContext.scope == Scope.IN_ARRAY ? ']' : '}'); currentContext = stack.pop(); popFieldContext(); return this; }
@Override public JsonGenerator writeStartObject(String name) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeChar('{'); stack.push(currentContext); currentContext = new Context(Scope.IN_OBJECT); return this; }
@Override public JsonGenerator writeStartArray(String name) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeChar('['); stack.push(currentContext); currentContext = new Context(Scope.IN_ARRAY); return this; }
@Override public JsonGenerator writeStartObject() { if (currentContext.scope == Scope.IN_OBJECT) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); } writeComma(); writeChar('{'); stack.push(currentContext); currentContext = new Context(Scope.IN_OBJECT); return this; }
@Override public JsonGenerator writeStartArray() { if (currentContext.scope == Scope.IN_OBJECT) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); } writeComma(); writeChar('['); stack.push(currentContext); currentContext = new Context(Scope.IN_ARRAY); return this; }
protected void writeColon() { writeChar(':'); }
protected void writeComma() { if (isCommaAllowed()) { writeChar(','); } currentContext.first = false; }
void writeEscapedString(String string) { writeChar('"'); int len = string.length(); for(int i = 0; i < len; i++) { case '"': case '\\': writeChar('\\'); writeChar(c); break; case '\b': writeChar('\\'); writeChar('b'); break; case '\f': writeChar('\\'); writeChar('f'); break; case '\n': writeChar('\\'); writeChar('n'); break; case '\r': writeChar('\\'); writeChar('r'); break; case '\t': writeChar('\\'); writeChar('t'); break; default: writeChar('"');
@Override public JsonGenerator writeEnd() { if (currentContext.scope == Scope.IN_NONE) { throw new JsonGenerationException("writeEnd() cannot be called in no context"); } writeChar(currentContext.scope == Scope.IN_ARRAY ? ']' : '}'); currentContext = stack.pop(); popFieldContext(); return this; }
@Override public JsonGenerator writeStartObject(String name) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeChar('{'); stack.push(currentContext); currentContext = new Context(Scope.IN_OBJECT); return this; }
@Override public JsonGenerator writeStartArray(String name) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeChar('['); stack.push(currentContext); currentContext = new Context(Scope.IN_ARRAY); return this; }
@Override public JsonGenerator writeStartObject() { if (currentContext.scope == Scope.IN_OBJECT) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); } writeComma(); writeChar('{'); stack.push(currentContext); currentContext = new Context(Scope.IN_OBJECT); return this; }
@Override public JsonGenerator writeStartArray() { if (currentContext.scope == Scope.IN_OBJECT) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } if (currentContext.scope == Scope.IN_NONE && !currentContext.first) { throw new JsonGenerationException(JsonMessages.GENERATOR_ILLEGAL_MULTIPLE_TEXT()); } writeComma(); writeChar('['); stack.push(currentContext); currentContext = new Context(Scope.IN_ARRAY); return this; }
protected void writeComma() { if (isCommaAllowed()) { writeChar(','); } currentContext.first = false; }
@Override public JsonGenerator writeStartObject(String name) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeChar('{'); stack.push(currentContext); currentContext = new Context(Scope.IN_OBJECT); return this; }
@Override public JsonGenerator writeStartArray(String name) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeChar('['); stack.push(currentContext); currentContext = new Context(Scope.IN_ARRAY); return this; }
@Override public JsonGenerator writeStartArray(String name) { if (currentContext.scope != Scope.IN_OBJECT) { throw new JsonGenerationException( JsonMessages.GENERATOR_ILLEGAL_METHOD(currentContext.scope)); } writeName(name); writeChar('['); stack.push(currentContext); currentContext = new Context(Scope.IN_ARRAY); return this; }