public class Json extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Json.ReadOnlySerializer<T> |
static interface |
Json.Serializable |
static interface |
Json.Serializer<T> |
| Constructor and Description |
|---|
Json() |
Json(JsonWriter.OutputType outputType) |
| Modifier and Type | Method and Description |
|---|---|
void |
addClassTag(String tag,
Class type)
Sets a tag to use instead of the fully qualifier class name.
|
void |
copyFields(Object from,
Object to)
Each field on the
to object is set to the value for the field with the same name on the from
object. |
<T> T |
fromJson(Class<T> type,
char[] data,
int offset,
int length) |
<T> T |
fromJson(Class<T> type,
Class elementType,
char[] data,
int offset,
int length) |
<T> T |
fromJson(Class<T> type,
Class elementType,
FileHandle file) |
<T> T |
fromJson(Class<T> type,
Class elementType,
InputStream input) |
<T> T |
fromJson(Class<T> type,
Class elementType,
Reader reader) |
<T> T |
fromJson(Class<T> type,
Class elementType,
String json) |
<T> T |
fromJson(Class<T> type,
FileHandle file) |
<T> T |
fromJson(Class<T> type,
InputStream input) |
<T> T |
fromJson(Class<T> type,
Reader reader) |
<T> T |
fromJson(Class<T> type,
String json) |
Class |
getClass(String tag)
Returns the class for the specified tag, or null.
|
boolean |
getIgnoreUnknownFields() |
<T> Json.Serializer<T> |
getSerializer(Class<T> type) |
String |
getTag(Class type)
Returns the tag for the specified class, or null.
|
JsonWriter |
getWriter() |
String |
prettyPrint(Object object) |
String |
prettyPrint(Object object,
int singleLineColumns) |
String |
prettyPrint(Object object,
JsonValue.PrettyPrintSettings settings) |
String |
prettyPrint(String json) |
String |
prettyPrint(String json,
int singleLineColumns) |
String |
prettyPrint(String json,
JsonValue.PrettyPrintSettings settings) |
void |
readField(Object object,
Field field,
String jsonName,
Class elementType,
JsonValue jsonMap) |
void |
readField(Object object,
String name,
Class elementType,
JsonValue jsonData) |
void |
readField(Object object,
String name,
JsonValue jsonData) |
void |
readField(Object object,
String fieldName,
String jsonName,
Class elementType,
JsonValue jsonMap) |
void |
readField(Object object,
String fieldName,
String jsonName,
JsonValue jsonData) |
void |
readFields(Object object,
JsonValue jsonMap) |
<T> T |
readValue(Class<T> type,
Class elementType,
JsonValue jsonData) |
<T> T |
readValue(Class<T> type,
Class elementType,
T defaultValue,
JsonValue jsonData) |
<T> T |
readValue(Class<T> type,
JsonValue jsonData) |
<T> T |
readValue(String name,
Class<T> type,
Class elementType,
JsonValue jsonMap) |
<T> T |
readValue(String name,
Class<T> type,
Class elementType,
T defaultValue,
JsonValue jsonMap) |
<T> T |
readValue(String name,
Class<T> type,
JsonValue jsonMap) |
<T> T |
readValue(String name,
Class<T> type,
T defaultValue,
JsonValue jsonMap) |
void |
setDefaultSerializer(Json.Serializer defaultSerializer)
Sets the serializer to use when the type being deserialized is not known (null).
|
void |
setDeprecated(Class type,
String fieldName,
boolean deprecated)
The specified field will be treated as if it has or does not have the
Deprecated annotation. |
void |
setElementType(Class type,
String fieldName,
Class elementType)
Sets the type of elements in a collection.
|
void |
setEnumNames(boolean enumNames)
When true,
Enum.name() is used to write enum values. |
void |
setIgnoreDeprecated(boolean ignoreDeprecated)
When true, fields with the
Deprecated annotation will not be read or written. |
void |
setIgnoreUnknownFields(boolean ignoreUnknownFields)
When true, fields in the JSON that are not found on the class will not throw a
SerializationException. |
void |
setOutputType(JsonWriter.OutputType outputType)
Default is
JsonWriter.OutputType.minimal. |
void |
setQuoteLongValues(boolean quoteLongValues)
Default is false.
|
void |
setReadDeprecated(boolean readDeprecated)
When true, fields with the
Deprecated annotation will be read (but not written) when
setIgnoreDeprecated(boolean) is true. |
<T> void |
setSerializer(Class<T> type,
Json.Serializer<T> serializer)
Registers a serializer to use for the specified type instead of the default behavior of serializing all of an objects
fields.
|
void |
setSortFields(boolean sortFields)
When true, fields are sorted alphabetically when written, otherwise the source code order is used.
|
void |
setTypeName(String typeName)
Sets the name of the JSON field to store the Java class name or class tag when required to avoid ambiguity during
deserialization.
|
void |
setUsePrototypes(boolean usePrototypes)
When true, field values that are identical to a newly constructed instance are not written.
|
void |
setWriter(Writer writer)
Sets the writer where JSON output will be written.
|
String |
toJson(Object object) |
String |
toJson(Object object,
Class knownType) |
String |
toJson(Object object,
Class knownType,
Class elementType) |
void |
toJson(Object object,
Class knownType,
Class elementType,
FileHandle file) |
void |
toJson(Object object,
Class knownType,
Class elementType,
Writer writer) |
void |
toJson(Object object,
Class knownType,
FileHandle file) |
void |
toJson(Object object,
Class knownType,
Writer writer) |
void |
toJson(Object object,
FileHandle file) |
void |
toJson(Object object,
Writer writer) |
void |
writeArrayEnd() |
void |
writeArrayStart() |
void |
writeArrayStart(String name) |
void |
writeField(Object object,
String name) |
void |
writeField(Object object,
String name,
Class elementType) |
void |
writeField(Object object,
String fieldName,
String jsonName) |
void |
writeField(Object object,
String fieldName,
String jsonName,
Class elementType)
Writes the specified field to the current JSON object.
|
void |
writeFields(Object object)
Writes all fields of the specified object to the current JSON object.
|
void |
writeObjectEnd() |
void |
writeObjectStart() |
void |
writeObjectStart(Class actualType,
Class knownType)
Starts writing an object, writing the actualType to a field if needed.
|
void |
writeObjectStart(String name) |
void |
writeObjectStart(String name,
Class actualType,
Class knownType) |
void |
writeType(Class type) |
void |
writeValue(Object value)
Writes the value, without writing the class of the object.
|
void |
writeValue(Object value,
Class knownType)
Writes the value, writing the class of the object if it differs from the specified known type.
|
void |
writeValue(Object value,
Class knownType,
Class elementType)
Writes the value, writing the class of the object if it differs from the specified known type.
|
void |
writeValue(String name,
Object value)
Writes the value as a field on the current JSON object, without writing the actual class.
|
void |
writeValue(String name,
Object value,
Class knownType)
Writes the value as a field on the current JSON object, writing the class of the object if it differs from the specified
known type.
|
void |
writeValue(String name,
Object value,
Class knownType,
Class elementType)
Writes the value as a field on the current JSON object, writing the class of the object if it differs from the specified
known type.
|
public Json()
public Json(JsonWriter.OutputType outputType)
public void setIgnoreUnknownFields(boolean ignoreUnknownFields)
SerializationException. Default is
false.public boolean getIgnoreUnknownFields()
public void setIgnoreDeprecated(boolean ignoreDeprecated)
Deprecated annotation will not be read or written. Default is false.public void setReadDeprecated(boolean readDeprecated)
Deprecated annotation will be read (but not written) when
setIgnoreDeprecated(boolean) is true. Default is false.setDeprecated(Class, String, boolean)public void setOutputType(JsonWriter.OutputType outputType)
JsonWriter.OutputType.minimal.JsonWriter.setOutputType(OutputType)public void setQuoteLongValues(boolean quoteLongValues)
JsonWriter.setQuoteLongValues(boolean)public void setEnumNames(boolean enumNames)
Enum.name() is used to write enum values. When false, Enum.toString() is used which may not be
unique. Default is true.public void addClassTag(String tag, Class type)
public void setTypeName(@Null String typeName)
public void setDefaultSerializer(@Null Json.Serializer defaultSerializer)
public <T> void setSerializer(Class<T> type, Json.Serializer<T> serializer)
public <T> Json.Serializer<T> getSerializer(Class<T> type)
public void setUsePrototypes(boolean usePrototypes)
public void setElementType(Class type, String fieldName, Class elementType)
public void setDeprecated(Class type, String fieldName, boolean deprecated)
Deprecated annotation.public void setSortFields(boolean sortFields)
public String toJson(@Null Object object, @Null Class knownType, @Null Class elementType)
knownType - May be null if the type is unknown.elementType - May be null if the type is unknown.public void toJson(@Null Object object, FileHandle file)
public void toJson(@Null Object object, @Null Class knownType, FileHandle file)
knownType - May be null if the type is unknown.public void toJson(@Null Object object, @Null Class knownType, @Null Class elementType, FileHandle file)
knownType - May be null if the type is unknown.elementType - May be null if the type is unknown.public void toJson(@Null Object object, @Null Class knownType, Writer writer)
knownType - May be null if the type is unknown.public void toJson(@Null Object object, @Null Class knownType, @Null Class elementType, Writer writer)
knownType - May be null if the type is unknown.elementType - May be null if the type is unknown.public void setWriter(Writer writer)
public JsonWriter getWriter()
public void writeFields(Object object)
public void writeField(Object object, String name, @Null Class elementType)
elementType - May be null if the type is unknown.writeField(Object, String, String, Class)public void writeField(Object object, String fieldName, String jsonName, @Null Class elementType)
elementType - May be null if the type is unknown.public void writeValue(String name, @Null Object value)
value - May be null.writeValue(String, Object, Class, Class)public void writeValue(String name, @Null Object value, @Null Class knownType)
value - May be null.knownType - May be null if the type is unknown.writeValue(String, Object, Class, Class)public void writeValue(String name, @Null Object value, @Null Class knownType, @Null Class elementType)
value - May be null.knownType - May be null if the type is unknown.elementType - May be null if the type is unknown.public void writeValue(@Null Object value)
value - May be null.public void writeValue(@Null Object value, @Null Class knownType)
value - May be null.knownType - May be null if the type is unknown.public void writeValue(@Null Object value, @Null Class knownType, @Null Class elementType)
value - May be null.knownType - May be null if the type is unknown.elementType - May be null if the type is unknown.public void writeObjectStart(String name)
public void writeObjectStart(String name, Class actualType, @Null Class knownType)
knownType - May be null if the type is unknown.public void writeObjectStart()
public void writeObjectStart(Class actualType, @Null Class knownType)
knownType - May be null if the type is unknown.public void writeObjectEnd()
public void writeArrayStart(String name)
public void writeArrayStart()
public void writeArrayEnd()
public void writeType(Class type)
@Null public <T> T fromJson(Class<T> type, Reader reader)
type - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, Class elementType, Reader reader)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, InputStream input)
type - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, Class elementType, InputStream input)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, FileHandle file)
type - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, Class elementType, FileHandle file)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, char[] data, int offset, int length)
type - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, Class elementType, char[] data, int offset, int length)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, String json)
type - May be null if the type is unknown.@Null public <T> T fromJson(Class<T> type, Class elementType, String json)
type - May be null if the type is unknown.public void readField(Object object, String name, @Null Class elementType, JsonValue jsonData)
public void readField(Object object, String fieldName, String jsonName, JsonValue jsonData)
public void readField(Object object, String fieldName, String jsonName, @Null Class elementType, JsonValue jsonMap)
elementType - May be null if the type is unknown.public void readField(@Null Object object, Field field, String jsonName, @Null Class elementType, JsonValue jsonMap)
object - May be null if the field is static.elementType - May be null if the type is unknown.@Null public <T> T readValue(String name, @Null Class<T> type, JsonValue jsonMap)
type - May be null if the type is unknown.@Null public <T> T readValue(String name, @Null Class<T> type, T defaultValue, JsonValue jsonMap)
type - May be null if the type is unknown.@Null public <T> T readValue(String name, @Null Class<T> type, @Null Class elementType, JsonValue jsonMap)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.@Null public <T> T readValue(String name, @Null Class<T> type, @Null Class elementType, T defaultValue, JsonValue jsonMap)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.@Null public <T> T readValue(@Null Class<T> type, @Null Class elementType, T defaultValue, JsonValue jsonData)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.@Null public <T> T readValue(@Null Class<T> type, JsonValue jsonData)
type - May be null if the type is unknown.@Null public <T> T readValue(@Null Class<T> type, @Null Class elementType, JsonValue jsonData)
type - May be null if the type is unknown.elementType - May be null if the type is unknown.public void copyFields(Object from, Object to)
to object is set to the value for the field with the same name on the from
object. The to object must have at least all the fields of the from object with the same name and
type.public String prettyPrint(@Null Object object, JsonValue.PrettyPrintSettings settings)
public String prettyPrint(String json, JsonValue.PrettyPrintSettings settings)
Copyright © 2021. All rights reserved.