Answer the question
In order to leave comments, you need to log in
json -> java mapping?
Is there any way to easily and naturally map a json document like this:
{
"columns" : [ "name", "description", "id" ],
"data" : [ [ "Train", "Поезда", 36 ], [ "Ship", "Корабли", 35 ], [ "Plane", "Самолеты", 34 ] ]
}
class Transport {
String id;
String name;
String description;
}
Answer the question
In order to leave comments, you need to log in
There are many great frameworks that allow you to serialize/deserialize JSON into java objects.
For example code.google.com/p/google-gson/
Try this tool - code.google.com/p/json-simple/
Works without problems and is quite convenient. In addition, some semblance of it is used in EE 7, where JSON support was added out of the box.
Wonderful tool - Jackson: wiki.fasterxml.com/JacksonHome
Specifically for your example, a powerful feature is that Jackson supports deserialization into polymorphic types. This is written here: github.com/FasterXML/jackson-annotations#handling-polymorphic-types
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question