Class JsonSerDeser<T>

java.lang.Object
org.apache.hadoop.util.JsonSerialization<T>
org.apache.hadoop.registry.client.binding.JsonSerDeser<T>
Type Parameters:
T - Type to marshal.
Direct Known Subclasses:
RegistryUtils.ServiceRecordMarshal

@Private @Evolving public class JsonSerDeser<T> extends org.apache.hadoop.util.JsonSerialization<T>
Support for marshalling objects to and from JSON.

This extends JsonSerialization with the notion of a marker field in the JSON file, with

  1. a fail-fast check for it before even trying to parse.
  2. Specific IOException subclasses for a failure.
The rationale for this is not only to support different things in the, registry, but the fact that all ZK nodes have a size > 0 when examined.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonSerDeser(Class<T> classType)
    Create an instance bound to a specific type
  • Method Summary

    Modifier and Type
    Method
    Description
    fromBytes(String path, byte[] bytes)
    Deserialize from a byte array
    fromBytes(String path, byte[] bytes, String marker)
    Deserialize from a byte array, optionally checking for a marker string.

    Methods inherited from class org.apache.hadoop.util.JsonSerialization

    fromBytes, fromInstance, fromJson, fromJsonStream, fromResource, getMapper, getName, load, load, load, mapReader, save, save, toBytes, toJson, toString, writeJsonAsBytes, writer

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • JsonSerDeser

      public JsonSerDeser(Class<T> classType)
      Create an instance bound to a specific type
      Parameters:
      classType - class to marshall
  • Method Details

    • fromBytes

      public T fromBytes(String path, byte[] bytes) throws IOException
      Deserialize from a byte array
      Parameters:
      path - path the data came from
      bytes - byte array
      Throws:
      IOException - all problems
      EOFException - not enough data
      InvalidRecordException - if the parsing failed -the record is invalid
      NoRecordException - if the data is not considered a record: either it is too short or it did not contain the marker string.
    • fromBytes

      public T fromBytes(String path, byte[] bytes, String marker) throws IOException
      Deserialize from a byte array, optionally checking for a marker string.

      If the marker parameter is supplied (and not empty), then its presence will be verified before the JSON parsing takes place; it is a fast-fail check. If not found, an InvalidRecordException exception will be raised

      Parameters:
      path - path the data came from
      bytes - byte array
      marker - an optional string which, if set, MUST be present in the UTF-8 parsed payload.
      Returns:
      The parsed record
      Throws:
      IOException - all problems
      EOFException - not enough data
      InvalidRecordException - if the JSON parsing failed.
      NoRecordException - if the data is not considered a record: either it is too short or it did not contain the marker string.