public final class Json extends Object
JsonPolicy,
Json instances are thread safe. Instances can be used across multiple threads. Currently, we
support adapters that listed in below as default.
- Primitive Types ({@code boolean}, {@code int}, {@code long} etc.)
- Wrapper Types ({@code Boolean}, {@code Integer}, {@code Long} etc.)
- {@code java.util.Date} Type
- {@code java.util.Calendar} Type
- Both Primitive and Generic Arrays
- Collection Types ({@code java.util.List}, {@code java.util.Set} etc)
- Map Types ({@code java.util.HashMap}, {@code java.util.LinkedHashMap} etc)
- Both Enum Serialization and Deserialization
- Nested Objects
See the {@link tr.com.terrayazilim.json.JsonPolicy} for default configuration options.
Usage notes: Json can serialize and deserialize generic and wildcard implementations. However, we
highly suggest avoid using hard-coded({@literal >}) wildcard types.
Error Codes definitions and possible solutions:
{@literal 101, 102}, Possibly forced JsonAdapter. Register {@code JsonAdapter} from
{@code JsonBuilder} or {@code JsonPolicy}.
{@literal 103, 104}, Possibly forced JsonSerializer or JsonDeserializer. See ErrorCode:101,
ErrorCode:102.
{@literal 105}, Invalid JSON String. {@literal 106}, Not registered and/or not recognizable
Object Type. {@literal 107}, Deserialization error. It occurs when the bean doesn't have default
constructor. Either create a default constructor in that bean or use {@code JsonDeserializer}.
{@literal 108}, Annotated Adapter doesn't have default, non-arg constructor. {@literal 109},
Annotated Serializer doesn't have default, non-arg constructor. {@literal 110}, Annotated
Deserializer doesn't have default, non-arg constructor. {@literal 111}, Arg of JsonLiteral
Constructor is not acceptable. See {@link tr.com.terrayazilim.json.JsonLiteral #isLiteral}
{@literal 112}, Status char is not any of [i, a, o , d, k]. This should never happen.
{@literal 113}, Parameter of JsonStream Constructor#JsonValue is not instance any of [JsonNull,
JsonLiteral, JsonObject, JsonArray]. It may occur when the hard-coded JsonValue trying to
register in JsonStream. {@literal 114}, See the ErrorCode:113. {@literal 115}, Unexpected
JsonStream Status. This should never happen. See the ErrorCode:113. {@literal 116,117,118,119},
JsonStream next# casting format problem.
| Constructor and Description |
|---|
Json() |
Json(JsonBuilder builder) |
Json(JsonPolicy policy) |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
fromJson(JsonObject jsonObject,
Token<T> token) |
<R> R |
fromJson(String json,
Token<R> token) |
<T> JsonAdapter<T> |
getAdapter(Token<T> typeToken)
Determines adapter in runtime.
|
<T> JsonDeserializer<T> |
getDeserializer(String key) |
JsonPolicy |
getPolicy()
It returns copy of
JsonPolicy, not the original one. |
<T> JsonSerializer<T> |
getSerializer(String key) |
static boolean |
isJson(String json) |
static boolean |
isJsonArray(String jsonArray) |
static boolean |
isJsonObject(String json) |
<R> String |
toJson(R instance,
int indent) |
<T> JsonObject |
toJson(T instance) |
<T> String |
toJson(T instance,
Token<T> token)
Use it for instances that has generic signature.
|
public Json(JsonBuilder builder)
builder - public Json()
public Json(JsonPolicy policy)
policy - public <T> JsonDeserializer<T> getDeserializer(String key)
T - key - public <T> JsonSerializer<T> getSerializer(String key)
T - key - public <T> JsonAdapter<T> getAdapter(Token<T> typeToken)
Determines adapter in runtime. It is thread safe and supports caching.
T - typeToken - public <T> JsonObject toJson(T instance)
T - instance - public <T> String toJson(T instance, Token<T> token)
Use it for instances that has generic signature.
T - instance - token - public <R> String toJson(R instance, int indent)
R - instance - indent - public <R> R fromJson(String json, Token<R> token)
R - json - token - public <T> T fromJson(JsonObject jsonObject, Token<T> token)
T - jsonObject - token - public JsonPolicy getPolicy()
JsonPolicy, not the original one.JsonPolicy.public static boolean isJson(String json)
json - public static boolean isJsonObject(String json)
json - public static boolean isJsonArray(String jsonArray)
jsonArray - Copyright © 2018 Terra Software Informatics LLC.. All rights reserved.