|
Project Information
Featured
Downloads
Links
|
What the heck is piritiPiriti (Maori for "bridge") is a JSON and XML mapper for GWT based on reasonable defaults, a handful of annotations and deferred binding. The following code snippets show the basic ideas behind Piriti. XML MappingIn case you have the following XML document <vub readonly="true">
<name>Foo</name>
<createdAt>08.01.2010</createdAt>
<count>20</count>
</vub>and the model class1 public class VirtualUserBundle
{
interface VubReader extends XmlReader<VirtualUserBundle> {}
public static final VubReader XML = GWT.create(VubReader.class);
int count;
String name;
@Path("@readonly") boolean readonly;
@Format("dd.MM.yyyy") Date createdAt;
}you can turn the XML into an instance of VirtualUserBundle by calling Document document = new XmlParser().parse(xmlAsString); VirtualUserBundle vub = VirtualUserBundle.XML.read(document); JSON MappingJSON mapping works very similar. In case you have the following JSON data { "readonly": true, "name": "Foo", "createdAt": "08.01.2010", "count": 20 }and the model class1 public class VirtualUserBundle
{
interface VubReader extends JsonReader<VirtualUserBundle> {}
public static final VubReader JSON = GWT.create(VubReader.class);
int count;
String name;
boolean readonly;
@Format("dd.MM.yyyy") Date createdAt;
}you can map the JSON data to an instance of VirtualUserBundle by calling String jsonString = ... // the above JSON data VirtualUserBundle vub = VirtualUserBundle.JSON.read(jsonString); I'm curiousFor further information take a look at the wiki: Spread the wordIf you like Piriti cheer for it on ohloh! 1 Classname taken from http://www.classnamer.com/. |