Class JsonSerDeser<T>
java.lang.Object
org.apache.hadoop.yarn.service.utils.JsonSerDeser<T>
- Type Parameters:
T-
- Direct Known Subclasses:
ApplicationReportSerDeser
Support for marshalling objects to and from JSON.
This class is NOT thread safe; it constructs an object mapper
as an instance field.
-
Constructor Summary
ConstructorsConstructorDescriptionJsonSerDeser(Class<T> classType) Create an instance bound to a specific typeJsonSerDeser(Class<T> classType, com.fasterxml.jackson.databind.PropertyNamingStrategy namingStrategy) -
Method Summary
Modifier and TypeMethodDescriptionfromBytes(byte[] b) Deserialize from a byte arrayConvert from a JSON filefromInstance(T instance) clone by converting to JSON and back again.Convert from JSONfromResource(String resource) Convert from a JSON filefromStream(InputStream stream) Convert from an input stream, closing the stream afterwards.load(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) Load from a Hadoop filesystemvoidsave(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, T instance, boolean overwrite) Save to a hadoop filesystemvoidSave an instance to a fileConvert an object to a JSON string
-
Constructor Details
-
JsonSerDeser
Create an instance bound to a specific type- Parameters:
classType- class type
-
JsonSerDeser
-
-
Method Details
-
fromJson
public T fromJson(String json) throws IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException Convert from JSON- Parameters:
json- input- Returns:
- the parsed JSON
- Throws:
IOException- IOcom.fasterxml.jackson.databind.JsonMappingException- failure to map from the JSON to this classcom.fasterxml.jackson.core.JsonParseException
-
fromFile
public T fromFile(File jsonFile) throws IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException Convert from a JSON file- Parameters:
jsonFile- input file- Returns:
- the parsed JSON
- Throws:
IOException- IO problemscom.fasterxml.jackson.databind.JsonMappingException- failure to map from the JSON to this classcom.fasterxml.jackson.core.JsonParseException
-
fromResource
public T fromResource(String resource) throws IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException Convert from a JSON file- Parameters:
resource- input file- Returns:
- the parsed JSON
- Throws:
IOException- IO problemscom.fasterxml.jackson.databind.JsonMappingException- failure to map from the JSON to this classcom.fasterxml.jackson.core.JsonParseException
-
fromStream
Convert from an input stream, closing the stream afterwards.- Parameters:
stream-- Returns:
- the parsed JSON
- Throws:
IOException- IO problems
-
fromInstance
clone by converting to JSON and back again. This is much less efficient than any Java clone process.- Parameters:
instance- instance to duplicate- Returns:
- a new instance
- Throws:
IOException- problems.
-
fromBytes
Deserialize from a byte array- Parameters:
b-- Returns:
- the deserialized value
- Throws:
IOException- parse problems
-
load
public T load(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException Load from a Hadoop filesystem- Parameters:
fs- filesystempath- path- Returns:
- a loaded CD
- Throws:
IOException- IO problemscom.fasterxml.jackson.core.JsonParseException- parse problemscom.fasterxml.jackson.databind.JsonMappingException- O/J mapping problems
-
save
public void save(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, T instance, boolean overwrite) throws IOException Save to a hadoop filesystem- Parameters:
fs- filesystempath- pathinstance- instance to saveoverwrite- should any existing file be overwritten- Throws:
IOException- IO exception
-
save
Save an instance to a file- Parameters:
instance- instance to savefile- file- Throws:
IOException
-
toJson
Convert an object to a JSON string- Parameters:
instance- instance to convert- Returns:
- a JSON string description
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- parse problems
-