org.apache.isis.viewer.restfulobjects.applib
Class JsonRepresentation

java.lang.Object
  extended by org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation
Direct Known Subclasses:
DomainRepresentation, ErrorRepresentation, LinkRepresentation

public class JsonRepresentation
extends Object

A wrapper around JsonNode that provides some additional helper methods.


Nested Class Summary
static interface JsonRepresentation.HasExtensions
           
static interface JsonRepresentation.HasLinks
           
static interface JsonRepresentation.LinksToSelf
           
 
Field Summary
protected  org.codehaus.jackson.JsonNode jsonNode
           
 
Constructor Summary
JsonRepresentation(org.codehaus.jackson.JsonNode jsonNode)
           
 
Method Summary
 void arrayAdd(boolean value)
           
 void arrayAdd(double value)
           
 void arrayAdd(float value)
           
 void arrayAdd(int value)
           
 void arrayAdd(org.codehaus.jackson.JsonNode value)
           
 void arrayAdd(JsonRepresentation value)
           
 void arrayAdd(long value)
           
 void arrayAdd(Object value)
           
 void arrayAdd(String value)
           
 JsonRepresentation arrayGet(int i)
           
 Iterable<JsonRepresentation> arrayIterable()
           
<T> Iterable<T>
arrayIterable(Class<T> requiredType)
           
 Iterator<JsonRepresentation> arrayIterator()
           
<T> Iterator<T>
arrayIterator(Class<T> requiredType)
           
 void arraySetElementAt(int i, JsonRepresentation objectRepr)
           
<T extends JsonRepresentation>
T
as(Class<T> cls)
          Convenience to simply "downcast".
 String asArg()
           
 JsonRepresentation asArray()
           
protected  org.codehaus.jackson.node.ArrayNode asArrayNode()
          Convert underlying representation into an array.
 BigDecimal asBigDecimal()
           
 BigInteger asBigInteger()
           
 Boolean asBoolean()
           
 Double asDouble()
           
 InputStream asInputStream()
           
 Integer asInt()
           
 org.codehaus.jackson.JsonNode asJsonNode()
           
 LinkRepresentation asLink()
           
 Long asLong()
           
 JsonRepresentation asMap()
           
 JsonRepresentation asNull()
           
protected  org.codehaus.jackson.node.ObjectNode asObjectNode()
          Convert underlying representation into an object (map).
 String asString()
           
 String asUrlEncoded()
           
 JsonRepresentation ensureArray()
          A reciprocal of the behaviour of the automatic dereferencing of arrays that occurs when there is only a single instance.
 JsonRepresentation getArray(String path)
           
 JsonRepresentation getArrayEnsured(String path)
           
 BigDecimal getBigDecimal(String path)
           
 BigInteger getBigInteger(String path)
           
 Boolean getBoolean(String path)
           
 Double getDouble(String path)
           
 Integer getInt(String path)
           
 LinkRepresentation getLink(String path)
           
 Long getLong(String path)
           
 JsonRepresentation getMap(String path)
           
 JsonRepresentation getNull(String path)
          Either returns a JsonRepresentation that indicates that the wrapped node has null value (ie isNull()), or returns null if there was no node with the provided path.
 JsonRepresentation getRepresentation(String pathTemplate, Object... args)
           
 String getString(String path)
           
 boolean isArray()
           
 boolean isArray(String path)
           
 boolean isBigDecimal()
           
 boolean isBigDecimal(String path)
           
 boolean isBigInteger()
           
 boolean isBigInteger(String path)
           
 boolean isBoolean()
           
 boolean isBoolean(String path)
           
 boolean isDouble()
           
 boolean isDouble(String path)
           
 boolean isInt()
           
 boolean isInt(String path)
           
 boolean isLink()
           
 boolean isLink(org.codehaus.jackson.JsonNode node)
           
 boolean isLink(String path)
           
 boolean isLong()
           
 boolean isLong(String path)
           
 boolean isMap()
           
 boolean isMap(String path)
           
 boolean isNull()
           
 Boolean isNull(String path)
          Indicates that the wrapped node has null value (ie isNull()), or returns null if there was no node with the provided path.
 boolean isString()
           
 boolean isString(String path)
           
 boolean isValue()
          Node is a value (nb: could be null).
 boolean mapHas(String key)
           
 Iterable<Map.Entry<String,JsonRepresentation>> mapIterable()
           
 Iterator<Map.Entry<String,JsonRepresentation>> mapIterator()
           
 void mapPut(String key, boolean value)
           
 void mapPut(String key, double value)
           
 void mapPut(String key, float value)
           
 void mapPut(String key, int value)
           
 void mapPut(String key, org.codehaus.jackson.JsonNode value)
           
 void mapPut(String key, JsonRepresentation value)
           
 void mapPut(String key, List<Object> value)
           
 void mapPut(String key, long value)
           
 void mapPut(String key, Object value)
           
 void mapPut(String key, String value)
           
 LinkRepresentation mapValueAsLink()
          Convert a representation that contains a single node representing a link into a LinkRepresentation.
static JsonRepresentation newArray()
           
static JsonRepresentation newArray(int initialSize)
           
static JsonRepresentation newMap(String... keyValuePairs)
           
 int size()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jsonNode

protected final org.codehaus.jackson.JsonNode jsonNode
Constructor Detail

JsonRepresentation

public JsonRepresentation(org.codehaus.jackson.JsonNode jsonNode)
Method Detail

newMap

public static JsonRepresentation newMap(String... keyValuePairs)

newArray

public static JsonRepresentation newArray()

newArray

public static JsonRepresentation newArray(int initialSize)

asJsonNode

public org.codehaus.jackson.JsonNode asJsonNode()

size

public int size()

isValue

public boolean isValue()
Node is a value (nb: could be null).


getRepresentation

public JsonRepresentation getRepresentation(String pathTemplate,
                                            Object... args)

isArray

public boolean isArray(String path)

isArray

public boolean isArray()

getArray

public JsonRepresentation getArray(String path)

asArray

public JsonRepresentation asArray()

getArrayEnsured

public JsonRepresentation getArrayEnsured(String path)

isMap

public boolean isMap(String path)

isMap

public boolean isMap()

getMap

public JsonRepresentation getMap(String path)

asMap

public JsonRepresentation asMap()

isBoolean

public boolean isBoolean(String path)

isBoolean

public boolean isBoolean()

getBoolean

public Boolean getBoolean(String path)

asBoolean

public Boolean asBoolean()

isBigInteger

public boolean isBigInteger(String path)

isBigInteger

public boolean isBigInteger()

getBigInteger

public BigInteger getBigInteger(String path)

asBigInteger

public BigInteger asBigInteger()

isBigDecimal

public boolean isBigDecimal(String path)

isBigDecimal

public boolean isBigDecimal()

getBigDecimal

public BigDecimal getBigDecimal(String path)

asBigDecimal

public BigDecimal asBigDecimal()

isInt

public boolean isInt(String path)

isInt

public boolean isInt()

getInt

public Integer getInt(String path)

asInt

public Integer asInt()

isLong

public boolean isLong(String path)

isLong

public boolean isLong()

getLong

public Long getLong(String path)

asLong

public Long asLong()

isDouble

public boolean isDouble(String path)

isDouble

public boolean isDouble()

getDouble

public Double getDouble(String path)

asDouble

public Double asDouble()

isString

public boolean isString(String path)

isString

public boolean isString()

getString

public String getString(String path)

asString

public String asString()

asArg

public String asArg()

isLink

public boolean isLink()

isLink

public boolean isLink(String path)

isLink

public boolean isLink(org.codehaus.jackson.JsonNode node)

getLink

public LinkRepresentation getLink(String path)

asLink

public LinkRepresentation asLink()

isNull

public boolean isNull()

isNull

public Boolean isNull(String path)
Indicates that the wrapped node has null value (ie isNull()), or returns null if there was no node with the provided path.


getNull

public JsonRepresentation getNull(String path)
Either returns a JsonRepresentation that indicates that the wrapped node has null value (ie isNull()), or returns null if there was no node with the provided path.


asNull

public JsonRepresentation asNull()

mapValueAsLink

public LinkRepresentation mapValueAsLink()
Convert a representation that contains a single node representing a link into a LinkRepresentation.


asInputStream

public InputStream asInputStream()

asArrayNode

protected org.codehaus.jackson.node.ArrayNode asArrayNode()
Convert underlying representation into an array.


asObjectNode

protected org.codehaus.jackson.node.ObjectNode asObjectNode()
Convert underlying representation into an object (map).


as

public <T extends JsonRepresentation> T as(Class<T> cls)
Convenience to simply "downcast".

In fact, the method creates a new instance of the specified type, which shares the underlying jsonNode.


asUrlEncoded

public String asUrlEncoded()

arrayAdd

public void arrayAdd(Object value)

arrayAdd

public void arrayAdd(JsonRepresentation value)

arrayAdd

public void arrayAdd(String value)

arrayAdd

public void arrayAdd(org.codehaus.jackson.JsonNode value)

arrayAdd

public void arrayAdd(long value)

arrayAdd

public void arrayAdd(int value)

arrayAdd

public void arrayAdd(double value)

arrayAdd

public void arrayAdd(float value)

arrayAdd

public void arrayAdd(boolean value)

arrayIterable

public Iterable<JsonRepresentation> arrayIterable()

arrayIterable

public <T> Iterable<T> arrayIterable(Class<T> requiredType)

arrayIterator

public Iterator<JsonRepresentation> arrayIterator()

arrayIterator

public <T> Iterator<T> arrayIterator(Class<T> requiredType)

arrayGet

public JsonRepresentation arrayGet(int i)

arraySetElementAt

public void arraySetElementAt(int i,
                              JsonRepresentation objectRepr)

mapHas

public boolean mapHas(String key)

mapPut

public void mapPut(String key,
                   List<Object> value)

mapPut

public void mapPut(String key,
                   Object value)

mapPut

public void mapPut(String key,
                   JsonRepresentation value)

mapPut

public void mapPut(String key,
                   String value)

mapPut

public void mapPut(String key,
                   org.codehaus.jackson.JsonNode value)

mapPut

public void mapPut(String key,
                   long value)

mapPut

public void mapPut(String key,
                   int value)

mapPut

public void mapPut(String key,
                   double value)

mapPut

public void mapPut(String key,
                   float value)

mapPut

public void mapPut(String key,
                   boolean value)

mapIterable

public Iterable<Map.Entry<String,JsonRepresentation>> mapIterable()

mapIterator

public Iterator<Map.Entry<String,JsonRepresentation>> mapIterator()

ensureArray

public JsonRepresentation ensureArray()
A reciprocal of the behaviour of the automatic dereferencing of arrays that occurs when there is only a single instance.

See Also:
toJsonNode(List)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.