Coder Social home page Coder Social logo

piriti's Introduction

What the heck is piriti

Piriti (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 Mapping

In 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 class

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 Mapping

JSON 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 class

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.