name.pehl.piriti.restlet.json.client
Class PiritiJsonRepresentation<T>

java.lang.Object
  extended by org.restlet.client.representation.Variant
      extended by org.restlet.client.representation.RepresentationInfo
          extended by org.restlet.client.representation.Representation
              extended by org.restlet.client.ext.json.JsonRepresentation
                  extended by name.pehl.piriti.restlet.json.client.PiritiJsonRepresentation<T>
Type Parameters:
T - The model type
All Implemented Interfaces:
PiritiRepresentation<T>

public class PiritiJsonRepresentation<T>
extends org.restlet.client.ext.json.JsonRepresentation
implements PiritiRepresentation<T>

Representation which uses an JsonReader for converting JSON to an instance of T.

Version:
$Date: 2011-03-20 21:02:59 +0100 (So, 20 Mär 2011) $ $Revision: 264 $
Author:
$Author: harald.pehl $

Field Summary
 
Fields inherited from class org.restlet.client.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
PiritiJsonRepresentation(JsonReader<T> jsonReader, org.restlet.client.data.MediaType mediaType)
          Constructor for an null JSON value.
PiritiJsonRepresentation(JsonReader<T> jsonReader, org.restlet.client.data.MediaType mediaType, com.google.gwt.json.client.JSONValue value)
          Constructor from an existing JSON value.
PiritiJsonRepresentation(JsonReader<T> jsonReader, org.restlet.client.representation.Representation jsonRepresentation)
          Constructor.
PiritiJsonRepresentation(JsonReader<T> jsonReader, String jsonString)
          Constructor from a JSON string.
 
Method Summary
 JsonReader<T> getJsonReader()
           
 T getModel()
          Converts the JSON to an instance of T using the JsonReader given as constructor argument.
 List<T> getModels()
          Converts the JSON to a list of Ts using the JsonReader given as constructor argument.
 
Methods inherited from class org.restlet.client.ext.json.JsonRepresentation
getJsonObject, getReader, getSize, getStream, getText, getValue, release, setValue
 
Methods inherited from class org.restlet.client.representation.Representation
append, exhaust, getAvailableSize, getDisposition, getExpirationDate, getRange, hasKnownSize, isAvailable, isEmpty, isTransient, setAvailable, setDisposition, setExpirationDate, setRange, setSize, setTransient
 
Methods inherited from class org.restlet.client.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
 
Methods inherited from class org.restlet.client.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PiritiJsonRepresentation

public PiritiJsonRepresentation(JsonReader<T> jsonReader,
                                org.restlet.client.data.MediaType mediaType)
Constructor for an null JSON value.

Parameters:
jsonReader - theJsonReader for converting the JSON to an instance of T.
mediaType - The representation's media type.

PiritiJsonRepresentation

public PiritiJsonRepresentation(JsonReader<T> jsonReader,
                                org.restlet.client.data.MediaType mediaType,
                                com.google.gwt.json.client.JSONValue value)
Constructor from an existing JSON value.

Parameters:
jsonReader - theJsonReader for converting the JSON to an instance of T.
mediaType - The representation's media type.
value - The source JSON value.

PiritiJsonRepresentation

public PiritiJsonRepresentation(JsonReader<T> jsonReader,
                                org.restlet.client.representation.Representation jsonRepresentation)
Constructor.

Parameters:
jsonReader - theJsonReader for converting the JSON to an instance of T.
jsonRepresentation - A source JSON representation to parse.

PiritiJsonRepresentation

public PiritiJsonRepresentation(JsonReader<T> jsonReader,
                                String jsonString)
Constructor from a JSON string.

Parameters:
jsonReader - theJsonReader for converting the JSON to an instance of T.
jsonString - The JSON string.
Method Detail

getJsonReader

public JsonReader<T> getJsonReader()
Returns:
the JsonReader for converting the JSON to an instance of T.

getModel

public T getModel()
           throws IOException
Converts the JSON to an instance of T using the JsonReader given as constructor argument. Returns null if JsonRepresentation.getJsonObject() or JsonReader is null.

Specified by:
getModel in interface PiritiRepresentation<T>
Returns:
the converted instance of T or null if JsonRepresentation.getJsonObject() or JsonReader is null.
Throws:
IOException

getModels

public List<T> getModels()
                  throws IOException
Converts the JSON to a list of Ts using the JsonReader given as constructor argument. Returns null if JsonRepresentation.getJsonObject() or JsonReader is null. More precisely the JSON has to be a JSON object with one key (name does not matter). The value of this key has to be a JSON array which is converted to instances of T.

Specified by:
getModels in interface PiritiRepresentation<T>
Returns:
the list of converted Ts or null if JsonRepresentation.getJsonObject() or JsonReader is null.
Throws:
IOException


Copyright © 2012 Harald Pehl. All Rights Reserved.