com.h3c.of.json

## Class OfJsonCodec<T extends Structure>

- java.lang.Object
- - com.h3c.util.json.AbstractJsonCodec<T>
  - - com.h3c.of.json.OfJsonCodec<T>

- Type Parameters:
    `T` - type of POJO for which a JSON codec is provided
  All Implemented Interfaces:
    JsonCodec<T>
  Direct Known Subclasses:
    ActionCodec, InstructionCodec, MatchFieldCodec, MBodyExperimenterCodec, MBodyFlowStatsCodec, MBodyGroupDescStatsCodec, MBodyGroupFeaturesCodec, MBodyGroupStatsCodec, MBodyMeterFeaturesCodec, MBodyMeterStatsCodec, MBodyPortStatsCodec, MeterCodec, OfmFlowModCodec, OfmGroupModCodec, OfmMeterModCodec, PortCodec

      public abstract class OfJsonCodec<T extends Structure>
      extends AbstractJsonCodec<T>

  The base JSON codec for all Openflow-related stuff, particularly all `Structure` classes. All JSON representations of the `Structure` will have an injected top-level "version" node that correspond to the version from `Structure.getVersion()`.

  Accordingly, the `JsonCodec.decode(ObjectNode)` method implemented by sub-classes of this class must ensure that the ObjectNode parameter indeed contains a "version" node so that it can re-hydrate the `Structure` POJO successfully.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `VERSION`

    - ### Fields inherited from class com.h3c.util.json.AbstractJsonCodec

      `log, mapper, NO_DECODING_SUP, root, roots`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `OfJsonCodec(String root, String roots)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `decode(String json)` Decodes the JSON string into a typed POJO.
    `List<T>` | `decodeList(String json)` Decodes the JSON string into a typed list of POJO.
    `String` | `encode(T pojo, boolean prettyPrint)` Encodes the given POJO to its JSON string representation.
    `String` | `encodeList(Collection<T> pojos, boolean prettyPrint)` Encodes the collection of POJOs to their JSON string representation.
    `protected ProtocolVersion` | `version(com.fasterxml.jackson.databind.node.ObjectNode node)` Retrieve the protocol version from a given json node that contains the `VERSION` tag.

    - ### Methods inherited from class com.h3c.util.json.AbstractJsonCodec

      `arrayNode, encodeList, fromEnums, isMissingContent, longVal, objectNode, read, root, roots, toEnums, write`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.h3c.util.json.JsonCodec

      `decode, encode`

- - ### Field Detail

    - #### VERSION

          public static final String VERSION

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### OfJsonCodec

          protected OfJsonCodec(String root,
                     String roots)

  - ### Method Detail

    - #### decode

          public T decode(String json)

      Description copied from interface: `JsonCodec`
      Decodes the JSON string into a typed POJO.
      Specified by:
        `decode` in interface `JsonCodec<T extends Structure>`
      Overrides:
        `decode` in class `AbstractJsonCodec<T extends Structure>`
      Parameters:
        `json` - JSON string representation of the typed POJO
      Returns:
        typed POJO

    - #### decodeList

          public List<T> decodeList(String json)

      Description copied from interface: `JsonCodec`
      Decodes the JSON string into a typed list of POJO.
      Specified by:
        `decodeList` in interface `JsonCodec<T extends Structure>`
      Overrides:
        `decodeList` in class `AbstractJsonCodec<T extends Structure>`
      Parameters:
        `json` - JSON string representation of the typed list of POJOs
      Returns:
        typed list of POJOs

    - #### encode

          public String encode(T pojo,
                      boolean prettyPrint)

      Description copied from interface: `JsonCodec`
      Encodes the given POJO to its JSON string representation.
      Specified by:
        `encode` in interface `JsonCodec<T extends Structure>`
      Overrides:
        `encode` in class `AbstractJsonCodec<T extends Structure>`
      Parameters:
        `pojo` - POJO to encode
        `prettyPrint` - Human-readable formatted JSON if true, single-line JSON otherwise
      Returns:
        JSON string representation of POJO

    - #### encodeList

          public String encodeList(Collection<T> pojos,
                          boolean prettyPrint)

      Description copied from interface: `JsonCodec`
      Encodes the collection of POJOs to their JSON string representation.
      Specified by:
        `encodeList` in interface `JsonCodec<T extends Structure>`
      Overrides:
        `encodeList` in class `AbstractJsonCodec<T extends Structure>`
      Parameters:
        `pojos` - list of POJO's to encode
        `prettyPrint` - human-readable formatted JSON if true, single-line JSON otherwise
      Returns:
        JSON string representation of the list of POJO's

    - #### version

          protected ProtocolVersion version(com.fasterxml.jackson.databind.node.ObjectNode node)

      Retrieve the protocol version from a given json node that contains the `VERSION` tag.
      Parameters:
        `node` - JSON node that contains the VERSION tag
      Returns:
        protocol version

Copyright © 2014. All Rights Reserved.