Package org.onosproject.rest
Class AbstractWebResource
- java.lang.Object
-
- org.onlab.rest.BaseResource
-
- org.onosproject.rest.AbstractWebResource
-
- All Implemented Interfaces:
CodecContext
- Direct Known Subclasses:
AbstractInjectionResource
public class AbstractWebResource extends BaseResource implements CodecContext
Abstract REST resource.
-
-
Constructor Summary
Constructors Constructor Description AbstractWebResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> JsonCodec<T>
codec(Class<T> entityClass)
Returns the JSON codec for the specified entity class.protected <T> com.fasterxml.jackson.databind.node.ObjectNode
encodeArray(Class<T> codecClass, String field, Iterable<T> items)
Returns JSON object wrapping the array encoding of the specified collection of items.<T> T
getService(Class<T> serviceClass)
Returns reference to the specified service implementation.com.fasterxml.jackson.databind.ObjectMapper
mapper()
Returns the JSON object mapper.com.fasterxml.jackson.databind.node.ArrayNode
newArray(com.fasterxml.jackson.databind.node.ObjectNode parent, String key)
Creates and returns a new child array within the specified parent and bound to the given key.com.fasterxml.jackson.databind.node.ObjectNode
newObject(com.fasterxml.jackson.databind.node.ObjectNode parent, String key)
Creates and returns a new child object within the specified parent and bound to the given key.-
Methods inherited from class org.onlab.rest.BaseResource
get, ok
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.onosproject.codec.CodecContext
decode, encode
-
-
-
-
Method Detail
-
mapper
public com.fasterxml.jackson.databind.ObjectMapper mapper()
Description copied from interface:CodecContext
Returns the JSON object mapper.- Specified by:
mapper
in interfaceCodecContext
- Returns:
- object mapper
-
codec
public <T> JsonCodec<T> codec(Class<T> entityClass)
Returns the JSON codec for the specified entity class.- Specified by:
codec
in interfaceCodecContext
- Type Parameters:
T
- entity type- Parameters:
entityClass
- entity class- Returns:
- JSON codec
-
encodeArray
protected <T> com.fasterxml.jackson.databind.node.ObjectNode encodeArray(Class<T> codecClass, String field, Iterable<T> items)
Returns JSON object wrapping the array encoding of the specified collection of items.- Type Parameters:
T
- item type- Parameters:
codecClass
- codec item classfield
- field holding the arrayitems
- collection of items to be encoded into array- Returns:
- JSON object
-
getService
public <T> T getService(Class<T> serviceClass)
Description copied from interface:CodecContext
Returns reference to the specified service implementation.- Specified by:
getService
in interfaceCodecContext
- Type Parameters:
T
- service type- Parameters:
serviceClass
- service class- Returns:
- service implementation; null if no implementation available for the class
-
newObject
public com.fasterxml.jackson.databind.node.ObjectNode newObject(com.fasterxml.jackson.databind.node.ObjectNode parent, String key)
Creates and returns a new child object within the specified parent and bound to the given key.- Parameters:
parent
- parent objectkey
- key for the new child object- Returns:
- child object
-
newArray
public com.fasterxml.jackson.databind.node.ArrayNode newArray(com.fasterxml.jackson.databind.node.ObjectNode parent, String key)
Creates and returns a new child array within the specified parent and bound to the given key.- Parameters:
parent
- parent objectkey
- key for the new child array- Returns:
- child array
-
-