T - Type to marshal.@InterfaceAudience.Private @InterfaceStability.Evolving public class JsonSerDeser<T> extends Object
It constructs an object mapper as an instance field. and synchronizes access to those methods which use the mapper
| Modifier and Type | Field and Description |
|---|---|
static String |
E_DATA_TOO_SHORT |
static String |
E_MISSING_MARKER_STRING |
static String |
E_NO_DATA |
| Constructor and Description |
|---|
JsonSerDeser(Class<T> classType)
Create an instance bound to a specific type
|
| 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.
|
T |
fromFile(File jsonFile)
Convert from a JSON file
|
T |
fromInstance(T instance)
clone by converting to JSON and back again.
|
T |
fromJson(String json)
Convert from JSON
|
T |
fromResource(String resource)
Convert from a JSON file
|
String |
getName()
Get the simple name of the class type to be marshalled
|
T |
load(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Load from a Hadoop filesystem
|
void |
save(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
T instance,
boolean overwrite)
Save a cluster description to a hadoop filesystem
|
byte[] |
toBytes(T instance)
Convert JSON To bytes
|
String |
toJson(T instance)
Convert an instance to a JSON string
|
String |
toString(T instance)
Convert an instance to a string form for output.
|
public static final String E_NO_DATA
public static final String E_DATA_TOO_SHORT
public static final String E_MISSING_MARKER_STRING
public String getName()
public T fromJson(String json) throws IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException
json - inputIOException - IO problemscom.fasterxml.jackson.core.JsonParseException - If the input is not well-formattedcom.fasterxml.jackson.databind.JsonMappingException - failure to map from the JSON to this classpublic T fromFile(File jsonFile) throws IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException
jsonFile - input fileIOException - IO problemscom.fasterxml.jackson.core.JsonParseException - If the input is not well-formattedcom.fasterxml.jackson.databind.JsonMappingException - failure to map from the JSON to this classpublic T fromResource(String resource) throws IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException
resource - input fileIOException - IO problemscom.fasterxml.jackson.core.JsonParseException - If the input is not well-formattedcom.fasterxml.jackson.databind.JsonMappingException - failure to map from the JSON to this classpublic T fromInstance(T instance) throws IOException
instance - instance to duplicateIOException - problems.public T load(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException
fs - filesystempath - pathIOException - IO problemsEOFException - if not enough bytes were read incom.fasterxml.jackson.core.JsonParseException - parse problemscom.fasterxml.jackson.databind.JsonMappingException - O/J mapping problemspublic void save(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
T instance,
boolean overwrite)
throws IOException
fs - filesystempath - pathoverwrite - should any existing file be overwrittenIOException - IO exceptionpublic byte[] toBytes(T instance) throws IOException
instance - instance to convertIOExceptionpublic T fromBytes(String path, byte[] bytes) throws IOException, InvalidRecordException
path - path the data came frombytes - byte arrayIOException - all problemsEOFException - not enough dataInvalidRecordException - if the parsing failed -the record is invalidpublic T fromBytes(String path, byte[] bytes, String marker) throws IOException, NoRecordException, InvalidRecordException
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
path - path the data came frombytes - byte arraymarker - an optional string which, if set, MUST be present in the
UTF-8 parsed payload.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.public String toJson(T instance) throws com.fasterxml.jackson.core.JsonProcessingException
instance - instance to convertcom.fasterxml.jackson.core.JsonProcessingException - Json generation problemsCopyright © 2008–2017 Apache Software Foundation. All rights reserved.