How to get JSON element type with Gson?

Viewed 18070

In a JSON file, each object inside the file is composed by different type of JSON elements. (integer, string, array, array of objects, etc.)

My target is to list all element name and corresponding type. May I know how can I do that in Gson? The purpose of this is for creating a Hive schema.

Example:

{
  "number": 1, 
  "ts": "1386848002", 
  "cmpg": [
    {
      "id": 476, 
      "mcp": 0, 
      "deals": [ ], 
      "cookie": "uid:123", 
      "bid": [
        {
          "bId": 0, 
          "status": "ZB", 
          "rmtchID": -1
        }
      ]
    }
  ]
}

Output:

number int,
ts String,
cmpg array<map<String, Object>> // not sure how to interpret this...
1 Answers
Related