org.apache.hadoop.registry.client.binding

## 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

      @InterfaceAudience.Private
       @InterfaceStability.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 and Description
    --- | ---
    `static String` | `E_DATA_TOO_SHORT`
    `static String` | `E_MISSING_MARKER_STRING`
    `static String` | `E_NO_DATA`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonSerDeser(Class<T> classType)` Create an instance bound to a specific type

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `fromBytes(String path, byte[] bytes)` Deserialize from a byte array
    `T` | `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, mapReader, save, save, toBytes, toJson, toString, writer`

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

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

- - ### Field Detail

    - #### E_NO_DATA

          public static final String E_NO_DATA

      See Also:
        Constant Field Values

    - #### E_DATA_TOO_SHORT

          public static final String E_DATA_TOO_SHORT

      See Also:
        Constant Field Values

    - #### E_MISSING_MARKER_STRING

          public static final String E_MISSING_MARKER_STRING

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### JsonSerDeser

          public JsonSerDeser(Class<T> classType)

      Create an instance bound to a specific type
      Parameters:
        `classType` - class to marshall

  - ### Method Detail

    - #### 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.

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.