public class SpincastJsonManager extends Object implements IJsonManager
| Constructor and Description |
|---|
SpincastJsonManager(com.google.inject.Provider<com.google.inject.Injector> guiceProvider,
IJsonObjectFactory jsonObjectFactory,
Set<IJsonMixinInfo> jsonMixinInfos,
ISpincastJsonManagerConfig spincastJsonManagerConfig) |
| Modifier and Type | Method and Description |
|---|---|
Object |
clone(Object originalObject)
Tries to clone an object to a
IJsonObject or
a IJsonArray, if the object is not of
a primitive type (or BigDecimal). |
Object |
clone(Object originalObject,
boolean mutable)
Tries to clone an object to a
IJsonObject or
a IJsonArray, if the object is not of
a primitive type (or BigDecimal). |
IJsonArray |
cloneJsonArray(IJsonArray jsonArray)
Deep copy of the
IJsonArray, so any
modification to the original won't affect the
clone, and vice-versa. |
IJsonArray |
cloneJsonArray(IJsonArray jsonArray,
boolean mutable)
Deep copy of the
IJsonArray, so any
modification to the original won't affect the
clone, and vice-versa. |
IJsonObject |
cloneJsonObject(IJsonObject jsonObject)
Deep copy of the
IJsonObject, so any
modification to the original won't affect the
clone, and vice-versa. |
IJsonObject |
cloneJsonObject(IJsonObject jsonObject,
boolean mutable)
Deep copy of the
IJsonObject, so any
modification to the original won't affect the
clone, and vice-versa. |
protected void |
configureEmptyBeans(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
protected void |
configureMixins(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
protected void |
configureObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Configuration of the ObjectMapper.
|
Object |
convertToNativeType(Object originalObject)
Convert a random object to a valid native Json type, if
it's not already.
|
IJsonObject |
create()
Creates an empty
JsonObject |
IJsonObject |
create(InputStream inputStream)
Creates a
JsonObject from an inputStream. |
IJsonObject |
create(Map<String,?> params)
Creates an empty
JsonObject based on the specified Map. |
IJsonObject |
create(String jsonString)
Creates a
JsonObject from a Json
String. |
IJsonArray |
createArray()
Creates an empty
JsonArray. |
IJsonArray |
createArray(InputStream inputStream)
Creates a
JsonArray from an inputStream. |
IJsonArray |
createArray(List<?> elements)
Creates a
JsonArray from a List
of elements. |
IJsonArray |
createArray(String jsonString)
Creates a
JsonArray from a Json
String. |
IJsonArrayImmutable |
createArrayImmutable(IJsonArray jsonArray)
Make a
IJsonArray immutable, no element
could be added or removed on it. |
IJsonObjectImmutable |
createImmutable(IJsonObject jsonObject)
Make a
IJsonObject immutable, no element
could be added or removed on it. |
protected com.fasterxml.jackson.databind.ObjectMapper |
createObjectManager()
Creates the ObjectMapper
|
<T> T |
fromJsonInputStream(InputStream inputStream,
Class<T> clazz)
Creates an instance of the specified
T type
from a Json inputStream. |
Map<String,Object> |
fromJsonInputStreamToMap(InputStream inputStream)
Creates a
Map<String, Object> from a Json inputStream. |
<T> T |
fromJsonString(String jsonString,
Class<T> clazz)
Creates an instance of the specified
T type
from a Json String. |
Map<String,Object> |
fromJsonStringToMap(String jsonString)
Creates a
Map<String, Object> from a Json
String. |
protected com.fasterxml.jackson.databind.JsonSerializer<Date> |
getDateSerializer() |
protected com.google.inject.Injector |
getGuice() |
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat |
getIso8601DateParser1() |
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat |
getIso8601DateParser2() |
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat |
getIso8601DateParser3() |
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat |
getIso8601DateParserDefault() |
protected com.fasterxml.jackson.core.util.DefaultPrettyPrinter |
getJacksonPrettyPrinter() |
protected String |
getJacksonPrettyPrinterIndentation() |
protected String |
getJacksonPrettyPrinterNewline() |
protected com.fasterxml.jackson.databind.JsonDeserializer<IJsonArray> |
getJsonArrayDeserializer() |
protected com.fasterxml.jackson.databind.JsonSerializer<IJsonArray> |
getJsonArraySerializer() |
protected Set<IJsonMixinInfo> |
getJsonMixinInfos() |
protected com.fasterxml.jackson.databind.JsonDeserializer<IJsonObject> |
getJsonObjectDeserializer() |
protected IJsonObjectFactory |
getJsonObjectFactory() |
protected com.fasterxml.jackson.databind.JsonSerializer<IJsonObject> |
getJsonObjectSerializer() |
protected com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
protected ISpincastJsonManagerConfig |
getSpincastJsonManagerConfig() |
protected void |
injectDependencies(Object obj)
Once the deserialization of an Object is done,
we inject dependencies using Guice.
|
Date |
parseDateFromJson(String str)
Currently support ISO 8601 encoded dates.
|
protected void |
registerCustomModules(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
protected void |
registerDateModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Register our custom serializers for dates.
|
protected void |
registerIJsonObjectModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Register our custom (de)serializers for IJsonObject
|
String |
toJsonString(Object obj)
Gets the
Json String representation of
the specified object. |
String |
toJsonString(Object obj,
boolean pretty)
Gets the
Json String representation of the
specified object. |
@Inject
public SpincastJsonManager(com.google.inject.Provider<com.google.inject.Injector> guiceProvider,
IJsonObjectFactory jsonObjectFactory,
@Nullable
Set<IJsonMixinInfo> jsonMixinInfos,
ISpincastJsonManagerConfig spincastJsonManagerConfig)
protected com.google.inject.Injector getGuice()
protected IJsonObjectFactory getJsonObjectFactory()
protected Set<IJsonMixinInfo> getJsonMixinInfos()
protected ISpincastJsonManagerConfig getSpincastJsonManagerConfig()
protected com.fasterxml.jackson.core.util.DefaultPrettyPrinter getJacksonPrettyPrinter()
protected String getJacksonPrettyPrinterNewline()
protected String getJacksonPrettyPrinterIndentation()
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat getIso8601DateParserDefault()
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat getIso8601DateParser1()
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat getIso8601DateParser2()
protected org.spincast.shaded.org.apache.commons.lang3.time.FastDateFormat getIso8601DateParser3()
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
protected com.fasterxml.jackson.databind.ObjectMapper createObjectManager()
protected void configureObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
protected void configureEmptyBeans(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
protected void configureMixins(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
protected com.fasterxml.jackson.databind.JsonSerializer<IJsonObject> getJsonObjectSerializer()
protected com.fasterxml.jackson.databind.JsonSerializer<IJsonArray> getJsonArraySerializer()
protected com.fasterxml.jackson.databind.JsonSerializer<Date> getDateSerializer()
protected com.fasterxml.jackson.databind.JsonDeserializer<IJsonObject> getJsonObjectDeserializer()
protected com.fasterxml.jackson.databind.JsonDeserializer<IJsonArray> getJsonArrayDeserializer()
protected void registerCustomModules(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
protected void registerIJsonObjectModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
protected void registerDateModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public String toJsonString(Object obj)
IJsonManagerJson String representation of
the specified object.toJsonString in interface IJsonManagerpublic String toJsonString(Object obj, boolean pretty)
IJsonManagerJson String representation of the
specified object.toJsonString in interface IJsonManagerpretty - if true, the generated
String will be formatted.protected void injectDependencies(Object obj)
public <T> T fromJsonString(String jsonString, Class<T> clazz)
IJsonManagerT type
from a Json String.fromJsonString in interface IJsonManagerpublic <T> T fromJsonInputStream(InputStream inputStream, Class<T> clazz)
IJsonManagerT type
from a Json inputStream.fromJsonInputStream in interface IJsonManagerpublic Map<String,Object> fromJsonStringToMap(String jsonString)
IJsonManagerMap<String, Object> from a Json
String.fromJsonStringToMap in interface IJsonManagerpublic Map<String,Object> fromJsonInputStreamToMap(InputStream inputStream)
IJsonManagerMap<String, Object> from a Json inputStream.fromJsonInputStreamToMap in interface IJsonManagerpublic IJsonObject create()
IJsonManagerJsonObjectcreate in interface IJsonManagerpublic IJsonObject create(String jsonString)
IJsonManagerJsonObject from a Json
String.create in interface IJsonManagerpublic IJsonObject create(Map<String,?> params)
IJsonManagerJsonObject based on the specified Map.
An attempt will be made to create a deep copy of every elements so
a modification won't affect any external referecen and vice-versa.create in interface IJsonManagerpublic IJsonObject create(InputStream inputStream)
IJsonManagerJsonObject from an inputStream.create in interface IJsonManagerpublic IJsonObjectImmutable createImmutable(IJsonObject jsonObject)
IJsonManagerIJsonObject immutable, no element
could be added or removed on it.createImmutable in interface IJsonManagerpublic IJsonArray createArray()
IJsonManagerJsonArray.createArray in interface IJsonManagerpublic IJsonArray createArray(String jsonString)
IJsonManagerJsonArray from a Json
String.createArray in interface IJsonManagerpublic IJsonArray createArray(List<?> elements)
IJsonManagerJsonArray from a List
of elements.createArray in interface IJsonManagerpublic IJsonArray createArray(InputStream inputStream)
IJsonManagerJsonArray from an inputStream.createArray in interface IJsonManagerpublic IJsonArrayImmutable createArrayImmutable(IJsonArray jsonArray)
IJsonManagerIJsonArray immutable, no element
could be added or removed on it.createArrayImmutable in interface IJsonManagerpublic Date parseDateFromJson(String str)
parseDateFromJson in interface IJsonManagerpublic IJsonObject cloneJsonObject(IJsonObject jsonObject)
IJsonManagerIJsonObject, so any
modification to the original won't affect the
clone, and vice-versa.
The resulting IJsonObject is mutable.
cloneJsonObject in interface IJsonManagerpublic IJsonObject cloneJsonObject(IJsonObject jsonObject, boolean mutable)
IJsonManagerIJsonObject, so any
modification to the original won't affect the
clone, and vice-versa.cloneJsonObject in interface IJsonManagermutable - if false, the resulting
IJsonArray and all its children
will be immutable.public IJsonArray cloneJsonArray(IJsonArray jsonArray)
IJsonManagerIJsonArray, so any
modification to the original won't affect the
clone, and vice-versa.
The resulting IJsonArray is mutable.
cloneJsonArray in interface IJsonManagerpublic IJsonArray cloneJsonArray(IJsonArray jsonArray, boolean mutable)
IJsonManagerIJsonArray, so any
modification to the original won't affect the
clone, and vice-versa.cloneJsonArray in interface IJsonManagermutable - if false, the resulting
IJsonArray and all its children
will be immutable.public Object convertToNativeType(Object originalObject)
IJsonManagerconvertToNativeType in interface IJsonManagerpublic Object clone(Object originalObject)
IJsonManagerIJsonObject or
a IJsonArray, if the object is not of
a primitive type (or BigDecimal).
The cloning is made by serializing the Object to a Json string, and deserializing back. So any (de)serialization rules apply.
The non primitive object will be cloned to a IJsonArray
if it is a :
clone in interface IJsonManagerpublic Object clone(Object originalObject, boolean mutable)
IJsonManagerIJsonObject or
a IJsonArray, if the object is not of
a primitive type (or BigDecimal).
The cloning is made by serializing the Object to a Json string, and deserializing back. So any (de)serialization rules apply.
The non primitive object will be cloned to a IJsonArray
if it is a :
clone in interface IJsonManagermutable - if false, the resulting
Object and all its potential children
will be immutable.Copyright © 2016. All rights reserved.