* Factory for JSON protocol objects
*/
public static class Factory implements TProtocolFactory {
+ protected boolean fieldNamesAsString_ = false;
+
+ public Factory() {}
+
+ public Factory(boolean fieldNamesAsString) {
+ fieldNamesAsString_ = fieldNamesAsString;
+ }
public TProtocol getProtocol(TTransport trans) {
- return new TJSONProtocol(trans);
+ return new TJSONProtocol(trans, fieldNamesAsString_);
}
}
// Reader that manages a 1-byte buffer
private LookaheadReader reader_ = new LookaheadReader();
+ // Write out the TField names as a string instead of the default integer value
+ private boolean fieldNamesAsString_ = false;
+
// Push a new JSON context onto the stack.
private void pushContext(JSONBaseContext c) {
contextStack_.push(context_);
super(trans);
}
+ public TJSONProtocol(TTransport trans, boolean fieldNamesAsString) {
+ super(trans);
+ fieldNamesAsString_ = fieldNamesAsString;
+ }
+
@Override
public void reset() {
contextStack_.clear();
@Override
public void writeFieldBegin(TField field) throws TException {
- writeJSONInteger(field.id);
+ if (fieldNamesAsString_) {
+ writeString(field.name);
+ } else {
+ writeJSONInteger(field.id);
+ }
writeJSONObjectStart();
writeJSONString(getTypeNameForTypeID(field.type));
}