-
Notifications
You must be signed in to change notification settings - Fork 0
<wiki:toc max_depth="1" />
To map references it is important that all readers are initialized before the first POJO is read. Initialized means the call of GWT.create() has to happen. As long as you declare your reader / writer instances as static members, Piriti will take care of this. Once you have your reader / writer instances outside of your POJO, you have to take care of the initialization by yourself. See reference requirements for more details.
If you want to have both JSON and XML readers you can share most of the settings, but will most likely have different paths. In this case you can use external mappings to overwrite the default path names. See external mappings for more details.
Suppose you got the following JSON data and you just want to map the "result" node to a "User" POJO.
{
"version":"1.0",
"retcode": 0,
"result": {
"name" : "Max",
"age" : 20
}
}
This can be done using the following approach:
JSONObject json = JSONParser.parseStrict(response.getText()).isObject();
JSONObject result = JsonPath.select(json, "@.result").isObject();
User user = UserReader.INSTANCE.read(result);