scrooge icon indicating copy to clipboard operation
scrooge copied to clipboard

JsonThriftSerializer produces invalid JSON for maps with integer/enum keys

Open arkadiyt opened this issue 10 years ago • 3 comments

Consider the following thrift struct:

struct TestStruct {
  1: optional map<i64, string> map;
}

When I serialize it with JsonThriftSerializer:

import com.twitter.scrooge.JsonThriftSerializer

val testStruct = TestStruct(Some(Map(1L -> "")))
val serializer = JsonThriftSerializer(TestStruct)
serializer.toString(testStruct)

I expect to get:

{"map":{"1":""}}

I actually get:

{"map":{1:""}}

which is not valid json. For instance attempting to parse with jq:

$ echo '{"map":{1:""}}' | jq .
parse error: Object keys must be strings at line 1, column 10

arkadiyt avatar May 21 '15 20:05 arkadiyt

We are actually just calling through to Thrift's JSON support, which it appears is broken.

Two ways forward:

  1. Figure out if the thrift was fixed in a later version.

  2. Write our own TProtocol that does a better job here.

johnynek avatar May 22 '15 00:05 johnynek

I'd be happy to help someone tackle either of 1 or 2.

mosesn avatar May 29 '16 18:05 mosesn

@johnynek do you remember what the denouement of this issue was on your end?

mosesn avatar May 09 '17 21:05 mosesn