T - Type to marshal.@Private
@Evolving
public class JsonSerialization<T>
extends java.lang.Object
org.apache.hadoop.registry.client.binding.JsonSerDeser,
which is now a subclass of this class.| Constructor | Description |
|---|---|
JsonSerialization(java.lang.Class<T> classType,
boolean failOnUnknownProperties,
boolean pretty) |
Create an instance bound to a specific type.
|
| Modifier and Type | Method | Description |
|---|---|---|
T |
fromBytes(byte[] bytes) |
Deserialize from a byte array.
|
T |
fromInstance(T instance) |
clone by converting to JSON and back again.
|
T |
fromJson(java.lang.String json) |
Convert from JSON.
|
T |
fromJsonStream(java.io.InputStream stream) |
Read from an input stream.
|
T |
fromResource(java.lang.String resource) |
Convert from a JSON file.
|
com.fasterxml.jackson.databind.ObjectMapper |
getMapper() |
Get the mapper of this class.
|
java.lang.String |
getName() |
Get the simple name of the class type to be marshalled.
|
T |
load(java.io.File jsonFile) |
Load from a JSON text file.
|
T |
load(FileSystem fs,
Path path) |
Load from a Hadoop filesystem.
|
T |
load(FileSystem fs,
Path path,
FileStatus status) |
Load from a Hadoop filesystem.
|
static com.fasterxml.jackson.databind.ObjectReader |
mapReader() |
|
void |
save(java.io.File file,
T instance) |
Save to a local file.
|
void |
save(FileSystem fs,
Path path,
T instance,
boolean overwrite) |
Save to a Hadoop filesystem.
|
byte[] |
toBytes(T instance) |
Convert JSON to bytes.
|
java.lang.String |
toJson(T instance) |
Convert an instance to a JSON string.
|
java.lang.String |
toString(T instance) |
Convert an instance to a string form for output.
|
void |
writeJsonAsBytes(T instance,
java.io.OutputStream dataOutputStream) |
Write the JSON as bytes, then close the stream.
|
static com.fasterxml.jackson.databind.ObjectWriter |
writer() |
public JsonSerialization(java.lang.Class<T> classType, boolean failOnUnknownProperties, boolean pretty)
classType - class to marshallfailOnUnknownProperties - fail if an unknown property is encountered.pretty - generate pretty (indented) output?public static com.fasterxml.jackson.databind.ObjectWriter writer()
public static com.fasterxml.jackson.databind.ObjectReader mapReader()
public java.lang.String getName()
public com.fasterxml.jackson.databind.ObjectMapper getMapper()
public T fromJson(java.lang.String json) throws java.io.IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException
json - inputjava.io.IOException - 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 fromJsonStream(java.io.InputStream stream) throws java.io.IOException
stream - stream to read fromjava.io.IOException - 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 load(java.io.File jsonFile) throws java.io.IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException
jsonFile - input filejava.io.IOException - 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 void save(java.io.File file,
T instance)
throws java.io.IOException
file - fileinstance - instancejava.io.IOException - IO exceptionpublic T fromResource(java.lang.String resource) throws java.io.IOException, com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException
resource - input filejava.io.IOException - 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 java.io.IOException
instance - instance to duplicatejava.io.IOException - IO problems.public T load(FileSystem fs, Path path) throws java.io.IOException
fs - filesystempath - pathPathIOException - JSON parse problemjava.io.IOException - IO problemspublic T load(FileSystem fs, Path path, @Nullable FileStatus status) throws java.io.IOException
fs - filesystempath - pathstatus - status of the file to open.PathIOException - JSON parse problemjava.io.EOFException - file status references an empty filejava.io.IOException - IO problemspublic void save(FileSystem fs, Path path, T instance, boolean overwrite) throws java.io.IOException
fs - filesystempath - pathoverwrite - should any existing file be overwritteninstance - instancejava.io.IOException - IO exception.public void writeJsonAsBytes(T instance, java.io.OutputStream dataOutputStream) throws java.io.IOException
instance - instance to writedataOutputStream - an output stream that will always be closedjava.io.IOException - on any failurepublic byte[] toBytes(T instance) throws java.io.IOException
instance - instance to convertjava.io.IOException - IO problemspublic T fromBytes(byte[] bytes) throws java.io.IOException
bytes - byte arrayjava.io.IOException - IO problemsjava.io.EOFException - not enough datapublic java.lang.String toJson(T instance) throws com.fasterxml.jackson.core.JsonProcessingException
instance - instance to convertcom.fasterxml.jackson.core.JsonProcessingException - Json generation problemspublic java.lang.String toString(T instance)
instance - non-null instanceCopyright © 2008–2025 Apache Software Foundation. All rights reserved.