Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EnumMetaData cast safer because a typedef'd enum does not have E… #181

Merged
merged 1 commit into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private Map<String, TField> computeFieldNameMap(Class<?> clazz) {
elementMetaData = metaData.valueMetaData;
}

if (TType.ENUM == elementMetaData.type) {
if (elementMetaData instanceof EnumMetaData) {
classMap.put(fieldName, ((EnumMetaData) elementMetaData).enumClass);
} else if (elementMetaData instanceof StructMetaData) {
classMap.put(fieldName, ((StructMetaData) elementMetaData).structClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
* TODO(Alex Roetter): Also add a new TEXT_PROTOCOL field to ThriftCodec
* <p>
* TODO: Support map enum keys specified as strings.
* TODO: Support string values for enums that have been typedef'd.
*/
public class TTextProtocol extends TProtocol {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private TTextProtocolTestMsg testMsg() {
.setV(Letter.BETA)
.setW(TestUnion.f2(4))
.setX(ImmutableList.of(TestUnion.f2(5), TestUnion.f1(base64Encoder.decode("SGVsbG8gV29ybGQ="))))
.setY(Letter.ALPHA)
;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@

"w": { "f2": 4 },

"x": [ { "f2": 5 }, {"f1": "SGVsbG8gV29ybGQ="} ]
"x": [ { "f2": 5 }, {"f1": "SGVsbG8gV29ybGQ="} ],

"y": 1
}
4 changes: 4 additions & 0 deletions src/test/thrift/TTextProtocolTest.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enum Letter {
ECHO = 5,
}

typedef Letter Moji

union TestUnion {
1: binary f1
2: i32 f2
Expand Down Expand Up @@ -91,6 +93,8 @@ struct TTextProtocolTestMsg {
21: required TestUnion w;

22: required list<TestUnion> x;

23: Moji y; // Does not support string values.
}

struct TTextProtocolTestMsgUnion {
Expand Down