THRIFT-5425 Throw an exception when reading TSimpleJson in Java
Client: java
Author: Thomas Bruggink
This closes #2400
Throw an exception when reading TSimpleJson and update the comment to explain why.
diff --git a/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java b/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
index 9413f61..38e10e1 100644
--- a/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java
@@ -368,112 +368,108 @@
/**
* Reading methods.
+ *
+ * simplejson is not meant to be read back into thrift
+ * - see http://wiki.apache.org/thrift/ThriftUsageJava
+ * - use JSON instead
*/
@Override
public TMessage readMessageBegin() throws TException {
- // TODO(mcslee): implement
- return EMPTY_MESSAGE;
+ throw new TException("Not implemented");
}
@Override
- public void readMessageEnd() throws TException {}
+ public void readMessageEnd() throws TException {
+ throw new TException("Not implemented");}
@Override
public TStruct readStructBegin() throws TException {
- // TODO(mcslee): implement
- return ANONYMOUS_STRUCT;
+ throw new TException("Not implemented");
}
@Override
- public void readStructEnd() throws TException {}
+ public void readStructEnd() throws TException {
+ throw new TException("Not implemented");}
@Override
public TField readFieldBegin() throws TException {
- // TODO(mcslee): implement
- return ANONYMOUS_FIELD;
+ throw new TException("Not implemented");
}
@Override
- public void readFieldEnd() throws TException {}
+ public void readFieldEnd() throws TException {
+ throw new TException("Not implemented");}
@Override
public TMap readMapBegin() throws TException {
- // TODO(mcslee): implement
- return EMPTY_MAP;
+ throw new TException("Not implemented");
}
@Override
- public void readMapEnd() throws TException {}
+ public void readMapEnd() throws TException {
+ throw new TException("Not implemented");}
@Override
public TList readListBegin() throws TException {
- // TODO(mcslee): implement
- return EMPTY_LIST;
+ throw new TException("Not implemented");
}
@Override
- public void readListEnd() throws TException {}
+ public void readListEnd() throws TException {
+ throw new TException("Not implemented");}
@Override
public TSet readSetBegin() throws TException {
- // TODO(mcslee): implement
- return EMPTY_SET;
+ throw new TException("Not implemented");
}
@Override
- public void readSetEnd() throws TException {}
+ public void readSetEnd() throws TException {
+ throw new TException("Not implemented");}
@Override
public boolean readBool() throws TException {
- return (readByte() == 1);
+ throw new TException("Not implemented");
}
@Override
public byte readByte() throws TException {
- // TODO(mcslee): implement
- return 0;
+ throw new TException("Not implemented");
}
@Override
public short readI16() throws TException {
- // TODO(mcslee): implement
- return 0;
+ throw new TException("Not implemented");
}
@Override
public int readI32() throws TException {
- // TODO(mcslee): implement
- return 0;
+ throw new TException("Not implemented");
}
@Override
public long readI64() throws TException {
- // TODO(mcslee): implement
- return 0;
+ throw new TException("Not implemented");
}
@Override
public double readDouble() throws TException {
- // TODO(mcslee): implement
- return 0;
+ throw new TException("Not implemented");
}
@Override
public String readString() throws TException {
- // TODO(mcslee): implement
- return "";
+ throw new TException("Not implemented");
}
public String readStringBody(int size) throws TException {
- // TODO(mcslee): implement
- return "";
+ throw new TException("Not implemented");
}
@Override
public ByteBuffer readBinary() throws TException {
- // TODO(mcslee): implement
- return ByteBuffer.wrap(new byte[0]);
+ throw new TException("Not implemented");
}
public static class CollectionMapKeyException extends TException {
diff --git a/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java b/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java
index 171a487..bc20e31 100644
--- a/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java
+++ b/lib/java/test/org/apache/thrift/protocol/TestTSimpleJSONProtocol.java
@@ -23,9 +23,11 @@
import junit.framework.TestCase;
import org.apache.thrift.Fixtures;
+import org.apache.thrift.TDeserializer;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TMemoryBuffer;
+import org.apache.thrift.transport.TTransportException;
import thrift.test.CompactProtoTestStruct;
import thrift.test.HolyMoley;
@@ -91,4 +93,15 @@
//
}
}
+
+ public void testReadingThrows() throws TTransportException {
+ String input = "{\"test\": \"value\"}";
+ TDeserializer deserializer = new TDeserializer(new TSimpleJSONProtocol.Factory());
+ try {
+ deserializer.fromString(Fixtures.oneOfEach, input);
+ fail("Was able to read SimpleJSON");
+ } catch (TException e) {
+ assertEquals("Not implemented", e.getMessage());
+ }
+ }
}