Package org.onosproject.codec
Class JsonCodec<T>
- java.lang.Object
 - 
- org.onosproject.codec.JsonCodec<T>
 
 
- 
public abstract class JsonCodec<T> extends Object
Abstraction of a codec capable for encoding/decoding arbitrary objects to/from JSON. 
- 
- 
Constructor Summary
Constructors Constructor Description JsonCodec() 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<T>decode(com.fasterxml.jackson.databind.node.ArrayNode json, CodecContext context)Decodes the specified JSON array into a collection of entities.Tdecode(com.fasterxml.jackson.databind.node.ObjectNode json, CodecContext context)Decodes the specified entity from JSON.com.fasterxml.jackson.databind.node.ArrayNodeencode(Iterable<T> entities, CodecContext context)Encodes the collection of the specified entities.com.fasterxml.jackson.databind.node.ObjectNodeencode(T entity, CodecContext context)Encodes the specified entity into JSON.protected static com.fasterxml.jackson.databind.node.ObjectNodeget(com.fasterxml.jackson.databind.JsonNode parent, int childIndex)Gets a child Object Node from a parent by index.protected static com.fasterxml.jackson.databind.node.ObjectNodeget(com.fasterxml.jackson.databind.node.ObjectNode parent, String childName)Gets a child Object Node from a parent by name. 
 - 
 
- 
- 
Method Detail
- 
encode
public com.fasterxml.jackson.databind.node.ObjectNode encode(T entity, CodecContext context)
Encodes the specified entity into JSON.- Parameters:
 entity- entity to encodecontext- encoding context- Returns:
 - JSON node
 - Throws:
 UnsupportedOperationException- if the codec does not support encode operations
 
- 
decode
public T decode(com.fasterxml.jackson.databind.node.ObjectNode json, CodecContext context)
Decodes the specified entity from JSON.- Parameters:
 json- JSON to decodecontext- decoding context- Returns:
 - decoded entity
 - Throws:
 UnsupportedOperationException- if the codec does not support decode operations
 
- 
encode
public com.fasterxml.jackson.databind.node.ArrayNode encode(Iterable<T> entities, CodecContext context)
Encodes the collection of the specified entities.- Parameters:
 entities- collection of entities to encodecontext- encoding context- Returns:
 - JSON array
 - Throws:
 UnsupportedOperationException- if the codec does not support encode operations
 
- 
decode
public List<T> decode(com.fasterxml.jackson.databind.node.ArrayNode json, CodecContext context)
Decodes the specified JSON array into a collection of entities.- Parameters:
 json- JSON array to decodecontext- decoding context- Returns:
 - collection of decoded entities
 - Throws:
 UnsupportedOperationException- if the codec does not support decode operations
 
- 
get
protected static com.fasterxml.jackson.databind.node.ObjectNode get(com.fasterxml.jackson.databind.node.ObjectNode parent, String childName)Gets a child Object Node from a parent by name. If the child is not found or does nor represent an object, null is returned.- Parameters:
 parent- parent objectchildName- name of child to query- Returns:
 - child object if found, null if not found or if not an object
 
 
- 
get
protected static com.fasterxml.jackson.databind.node.ObjectNode get(com.fasterxml.jackson.databind.JsonNode parent, int childIndex)Gets a child Object Node from a parent by index. If the child is not found or does nor represent an object, null is returned.- Parameters:
 parent- parent objectchildIndex- index of child to query- Returns:
 - child object if found, null if not found or if not an object
 
 
 - 
 
 -