@Override public void serialize(String str, JsonGenerator gen, SerializerProvider provider) throws IOException { int status = ((JsonWriteContext) gen.getOutputContext()).writeValue(); switch (status) { case JsonWriteContext.STATUS_OK_AFTER_COLON: gen.writeRaw(':'); break; case JsonWriteContext.STATUS_OK_AFTER_COMMA: gen.writeRaw(','); break; case JsonWriteContext.STATUS_EXPECT_NAME: throw new JsonGenerationException("Can not write string value here"); } gen.writeRaw('"'); for (char c : str.toCharArray()) { if (c >= 0x80) writeUnicodeEscape(gen, c); // use generic escaping for all non US-ASCII characters else { // use escape table for first 128 characters int code = (c < ESCAPE_CODES.length ? ESCAPE_CODES[c] : 0); if (code == 0) gen.writeRaw(c); // no escaping else if (code == -1) writeUnicodeEscape(gen, c); // generic escaping else writeShortEscape(gen, (char) code); // short escaping (\n \t ...) } } gen.writeRaw('"'); }
protected GeneratorBase(ObjectWriteContext writeCtxt, int features) { super(); _objectWriteContext = writeCtxt; _features = features; DupDetector dups = Feature.STRICT_DUPLICATE_DETECTION.enabledIn(features) ? DupDetector.rootDetector(this) : null; _outputContext = JsonWriteContext.createRootContext(dups); _cfgNumbersAsStrings = Feature.WRITE_NUMBERS_AS_STRINGS.enabledIn(features); }
protected GeneratorBase(ObjectWriteContext writeCtxt, int features, JsonWriteContext ctxt) { super(); _objectWriteContext = writeCtxt; _features = features; _outputContext = ctxt; _cfgNumbersAsStrings = Feature.WRITE_NUMBERS_AS_STRINGS.enabledIn(features); }
public TokenBuffer(ObjectCodec paramObjectCodec) { this._objectCodec = paramObjectCodec; this._generatorFeatures = DEFAULT_PARSER_FEATURES; this._writeContext = JsonWriteContext.createRootContext(); Segment localSegment = new Segment(); this._last = localSegment; this._first = localSegment; this._appendOffset = 0; }
public final void writeEndArray() { _append(JsonToken.END_ARRAY); JsonWriteContext localJsonWriteContext = this._writeContext.getParent(); if (localJsonWriteContext != null) this._writeContext = localJsonWriteContext; }
public final void writeEndObject() { _append(JsonToken.END_OBJECT); JsonWriteContext localJsonWriteContext = this._writeContext.getParent(); if (localJsonWriteContext != null) this._writeContext = localJsonWriteContext; }
public GeneratorBase(int paramInt, ObjectCodec paramObjectCodec) { this._features = paramInt; this._writeContext = JsonWriteContext.createRootContext(); this._objectCodec = paramObjectCodec; this._cfgNumbersAsStrings = isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS); }
@Override protected void _verifyValueWrite(String typeMsg) throws IOException, JsonGenerationException { int status = _writeContext.writeValue(); if (status == JsonWriteContext.STATUS_EXPECT_NAME) { _reportError("Can not "+typeMsg+", expecting field name"); } }
@Override public final void writeFieldName(String name) throws IOException, JsonGenerationException { if (_writeContext.writeFieldName(name) == JsonWriteContext.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); } _writeFieldName(name); }
@Override public final void writeFieldName(SerializableString name) throws IOException, JsonGenerationException { // Object is a value, need to verify it's allowed if (_writeContext.writeFieldName(name.getValue()) == JsonWriteContext.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); } _writeFieldName(name); }
@Override public final void writeStringField(String fieldName, String value) throws IOException, JsonGenerationException { if (_writeContext.writeFieldName(fieldName) == JsonWriteContext.STATUS_EXPECT_VALUE) { _reportError("Can not write a field name, expecting a value"); } _writeFieldName(fieldName); writeString(value); }
@Override protected final void _verifyValueWrite(String typeMsg) throws IOException, JsonGenerationException { int status = _writeContext.writeValue(); if (status == JsonWriteContext.STATUS_EXPECT_NAME) { _reportError("Can not "+typeMsg+", expecting field name"); } }
protected GeneratorBase(int features, ObjectCodec codec) { super(); _features = features; DupDetector dups = Feature.STRICT_DUPLICATE_DETECTION.enabledIn(features) ? DupDetector.rootDetector(this) : null; _writeContext = JsonWriteContext.createRootContext(dups); _objectCodec = codec; _cfgNumbersAsStrings = Feature.WRITE_NUMBERS_AS_STRINGS.enabledIn(features); }
/** * @param codec Object codec to use for stream-based object * conversion through parser/generator interfaces. If null, * such methods can not be used. */ public TokenBuffer(ObjectCodec codec) { _objectCodec = codec; _generatorFeatures = DEFAULT_PARSER_FEATURES; _writeContext = JsonWriteContext.createRootContext(); // at first we have just one segment _first = _last = new Segment(); _appendOffset = 0; }
@Override public final void writeEndArray() throws IOException, JsonGenerationException { _append(JsonToken.END_ARRAY); // Let's allow unbalanced tho... i.e. not run out of root level, ever JsonWriteContext c = _writeContext.getParent(); if (c != null) { _writeContext = c; } }
@Override public final void writeEndObject() throws IOException, JsonGenerationException { _append(JsonToken.END_OBJECT); // Let's allow unbalanced tho... i.e. not run out of root level, ever JsonWriteContext c = _writeContext.getParent(); if (c != null) { _writeContext = c; } }
protected GeneratorBase(int features, ObjectCodec codec) { super(); _features = features; _writeContext = JsonWriteContext.createRootContext(); _objectCodec = codec; _cfgNumbersAsStrings = isEnabled(Feature.WRITE_NUMBERS_AS_STRINGS); }
public final JsonWriteContext getOutputContext() { return this._writeContext; }
@Override public final JsonWriteContext getOutputContext() { return _writeContext; }
/** * Note: co-variant return type. */ @Override public final JsonWriteContext getOutputContext() { return _writeContext; }