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
- a fail-fast check for it before even trying to parse.
- Specific IOException subclasses for a failure.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJsonSerDeser(Class<T> classType) Create an instance bound to a specific type -
Method Summary
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
-
Field Details
-
E_NO_DATA
- See Also:
-
E_DATA_TOO_SHORT
- See Also:
-
E_MISSING_MARKER_STRING
- See Also:
-
-
Constructor Details
-
JsonSerDeser
Create an instance bound to a specific type- Parameters:
classType- class to marshall
-
-
Method Details
-
fromBytes
Deserialize from a byte array- Parameters:
path- path the data came frombytes- byte array- Throws:
IOException- all problemsEOFException- not enough dataInvalidRecordException- if the parsing failed -the record is invalidNoRecordException- if the data is not considered a record: either it is too short or it did not contain the marker string.
-
fromBytes
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
InvalidRecordExceptionexception will be raised- Parameters:
path- path the data came frombytes- byte arraymarker- an optional string which, if set, MUST be present in the UTF-8 parsed payload.- Returns:
- The parsed record
- Throws:
IOException- all problemsEOFException- not enough dataInvalidRecordException- 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.
-