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, org.codehaus.jackson.JsonParseException, org.codehaus.jackson.map.JsonMappingException
json - inputIOException - IOorg.codehaus.jackson.map.JsonMappingException - failure to map from the JSON to this classorg.codehaus.jackson.JsonParseExceptionpublic T fromFile(File jsonFile) throws IOException, org.codehaus.jackson.JsonParseException, org.codehaus.jackson.map.JsonMappingException
jsonFile - input fileIOException - IO problemsorg.codehaus.jackson.map.JsonMappingException - failure to map from the JSON to this classorg.codehaus.jackson.JsonParseExceptionpublic T fromResource(String resource) throws IOException, org.codehaus.jackson.JsonParseException, org.codehaus.jackson.map.JsonMappingException
resource - input fileIOException - IO problemsorg.codehaus.jackson.map.JsonMappingException - failure to map from the JSON to this classorg.codehaus.jackson.JsonParseExceptionpublic 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, org.codehaus.jackson.JsonParseException, org.codehaus.jackson.map.JsonMappingException
fs - filesystempath - pathIOException - IO problemsEOFException - if not enough bytes were read inorg.codehaus.jackson.JsonParseException - parse problemsorg.codehaus.jackson.map.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 IOException, org.codehaus.jackson.JsonGenerationException, org.codehaus.jackson.map.JsonMappingException
instance - instance to convertorg.codehaus.jackson.JsonParseException - parse problemsorg.codehaus.jackson.map.JsonMappingException - O/J mapping problemsIOExceptionorg.codehaus.jackson.JsonGenerationExceptionCopyright © 2022 Apache Software Foundation. All rights reserved.