Skip to content

Commit

Permalink
... and add the writeFieldId() method actually
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 30, 2016
1 parent 792de08 commit 4601785
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,20 @@ public void writeStartObject(Object forValue) throws IOException
*/
public abstract void writeFieldName(SerializableString name) throws IOException;

/**
* Alternative to {@link #writeFieldName(String)} that may be used
* in cases where property key is of numeric type; either where
* underlying format supports such notion (some binary formats do,
* unlike JSON), or for convenient conversion into String presentation.
* Default implementation will simply convert id into <code>String</code>
* and call {@link #writeFieldName(String)}.
*
* @since 2.8
*/
public void writeFieldId(long id) throws IOException {
writeFieldName(Long.toString(id));
}

/*
/**********************************************************
/* Public API, write methods, scalar arrays (2.8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class JsonWriteContext extends JsonStreamContext
*/

/**
* Name of the field of which value is to be parsed; only
* Name of the field of which value is to be written; only
* used for OBJECT contexts
*/
protected String _currentName;
Expand All @@ -55,8 +55,8 @@ public class JsonWriteContext extends JsonStreamContext
protected Object _currentValue;

/**
* Marker used to indicate that we just received a name, and
* now expect a value
* Marker used to indicate that we just wrote a name, and
* now expect a value to write
*/
protected boolean _gotName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public JsonGenerator setPrettyPrinter(PrettyPrinter pp) {

@Override
public void writeStartObject(Object forValue) throws IOException { delegate.writeStartObject(forValue); }

@Override
public void writeEndObject() throws IOException { delegate.writeEndObject(); }

Expand All @@ -217,6 +217,11 @@ public void writeFieldName(SerializableString name) throws IOException {
delegate.writeFieldName(name);
}

@Override
public void writeFieldId(long id) throws IOException {
delegate.writeFieldId(id);
}

@Override
public void writeArray(int[] array, int offset, int length) throws IOException {
delegate.writeArray(array, offset, length);
Expand Down

0 comments on commit 4601785

Please sign in to comment.