0

I want to parse Wikimedia results with ObjectMapper. Here is the JSON structure:

{
  "continue1" : {
    "rdcontinue" : "!!!|12723219",
    "continue1" : "||"
  },
  "query" : {
    "pages" : {
      "3632887" : {
        "pageid" : 3632887,
        "ns" : 0,
        "title" : "!!",
        "redirects" : [ {
          "pageid" : 3122689,
          "ns" : 0,
          "title" : "‼"
        }, {
          "pageid" : 36372278,
          "ns" : 0,
          "title" : "!! (disambiguation)"
        }, {
          "pageid" : 37523807,
          "ns" : 0,
          "title" : "‼ (disambiguation)"
        } ]
      },
      "16381751" : {
        "pageid" : 16381751,
        "ns" : 0,
        "title" : "!!Destroy-Oh-Boy!!"
      },
      "2978668" : {
        "pageid" : 2978668,
        "ns" : 0,
        "title" : "!Action Pact!"
      }
    }
  }
}

Notice the varying entry id's: 3632887, 16381751, 2978668...

What should be my Java class hierarchical structure?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
BobR
  • 273
  • 3
  • 10
  • Use a `TypeReference` (Jackson) instead of a `TypeToken` (gson). – Sotirios Delimanolis Jul 15 '15 at 18:14
  • Use a `Map` to hold query.pages, where the key is the varying ID, and the value is an object containing pageid, ns, etc. – JB Nizet Jul 15 '15 at 18:14
  • I appreciate your answers, and I've just spent several hours trying the TypeReference (Jackson) approach, rather than gson, because that's what I'm used to. I understand the Map mechanism at the top level, but am having trouble structuring the classes for one nested readValue at once. Any suggestions greatly appreciated!! – BobR Jul 16 '15 at 15:34

0 Answers0