0

I successfully followed the example Simple Spring code to parse JSON into a Java class structure using Jackson.

Now i am looking for a hint how to do the same for JSON data without key names, e.g.

{
    "10869918": {
        "BRANCH": "Dienstleistungen", 
        "SECTOR": "Diverse"
    }, 
    "12254991": {
        "BRANCH": "Luft- und Raumfahrtindustrie", 
        "SECTOR": "Logistik"
    }, 
    "12302743": {
        "BRANCH": "Touristik und Freizeit", 
        "SECTOR": "Medien/Freizeit"
    }
}
3
  • @JamesB I think OP referes to the fact that the keys, like 10869918, cannot be the name of any attribute in a bean. The only option here is a Map<String,Map<String,String>> Commented Jul 7, 2014 at 14:17
  • What does the POJO look like that you are trying to map this json to? Commented Jul 7, 2014 at 14:47
  • I only have the JSON data and try to create suitable POJOs which match the data using Spring-Roo as rapid prototyping tool. The actual data set is more complex then the excerpt shown above. Commented Jul 7, 2014 at 15:05

1 Answer 1

2

I doubt this is possible with a POJO-JSON mapper. You could use libraries like json-simple to parse the JSON string into Java objects (which basically are maps and lists) and access values like "10869918" by reading the keys of those maps.

Sign up to request clarification or add additional context in comments.

1 Comment

My idea exactly; don't map to an object, map to a collection instead. The data itself seems to represent a hashtable of sorts anyway, so it would be pretty strange to want to map that to a POJO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.