@Component(value="cuba_EntitySerialization") public class EntitySerialization extends java.lang.Object implements EntitySerializationAPI
Modifier and Type | Class and Description |
---|---|
protected static class |
EntitySerialization.DateDeserializer |
protected static class |
EntitySerialization.DateSerializer |
protected class |
EntitySerialization.EntityDeserializer |
protected static class |
EntitySerialization.EntitySerializationContext
Class is used for storing a collection of entities already processed during the serialization.
|
protected class |
EntitySerialization.EntitySerializer |
Modifier and Type | Field and Description |
---|---|
protected java.lang.ThreadLocal<EntitySerialization.EntitySerializationContext> |
context |
protected DynamicAttributes |
dynamicAttributes |
protected GlobalConfig |
globalConfig |
protected Metadata |
metadata |
protected MetadataTools |
metadataTools |
ENTITY_NAME_PROP, INSTANCE_NAME_PROP, NAME
Constructor and Description |
---|
EntitySerialization() |
Modifier and Type | Method and Description |
---|---|
protected com.google.gson.Gson |
createGsonForDeserialization(com.haulmont.chile.core.model.MetaClass metaClass,
EntitySerializationOption... options) |
protected com.google.gson.Gson |
createGsonForSerialization(View view,
EntitySerializationOption... options) |
<T extends Entity> |
entitiesCollectionFromJson(java.lang.String json,
com.haulmont.chile.core.model.MetaClass metaClass,
EntitySerializationOption... options)
Deserializes a JSON array of objects to entities collection
|
<T extends Entity> |
entityFromJson(java.lang.String json,
com.haulmont.chile.core.model.MetaClass metaClass,
EntitySerializationOption... options)
Deserializes a JSON object to the entity.
|
protected java.lang.reflect.Field |
getField(java.lang.Class clazz,
java.lang.String fieldName) |
protected boolean |
isCollectionDynamicAttribute(com.haulmont.chile.core.model.MetaProperty metaProperty) |
protected void |
makeFieldAccessible(java.lang.reflect.Field field) |
<T> T |
objectFromJson(java.lang.String json,
java.lang.Class<T> clazz,
EntitySerializationOption... options)
Deserializes an object of any class from JSON.
|
java.lang.String |
objectToJson(java.lang.Object object,
EntitySerializationOption... options)
Serializes any custom POJO or collection of POJOs or JSON.
|
java.lang.String |
toJson(java.util.Collection<? extends Entity> entities)
An overloaded version of the
EntitySerializationAPI.toJson(Collection, View, EntitySerializationOption...) method with a null
view parameter and with no serialization options. |
java.lang.String |
toJson(java.util.Collection<? extends Entity> entities,
View view,
EntitySerializationOption... options)
Serializes a collection of entities to the JSON array.
|
java.lang.String |
toJson(Entity entity)
An overloaded version of the
EntitySerializationAPI.toJson(Entity, View, EntitySerializationOption...) method with a null
view parameter and with no serialization options. |
java.lang.String |
toJson(Entity entity,
View view,
EntitySerializationOption... options)
Serializes a single entity to the JSON object graph.
|
@Inject protected MetadataTools metadataTools
@Inject protected Metadata metadata
@Inject protected DynamicAttributes dynamicAttributes
@Inject protected GlobalConfig globalConfig
protected java.lang.ThreadLocal<EntitySerialization.EntitySerializationContext> context
public java.lang.String toJson(Entity entity)
EntitySerializationAPI
EntitySerializationAPI.toJson(Entity, View, EntitySerializationOption...)
method with a null
view
parameter and with no serialization options.toJson
in interface EntitySerializationAPI
entity
- an entity to be serializedpublic java.lang.String toJson(Entity entity, @Nullable View view, EntitySerializationOption... options)
EntitySerializationAPI
If the view
parameter is null then all loaded entity properties will be presented in JSON, otherwise only
loaded properties that are in the view will be in the JSON object.
The options
parameter specify some additional options for the serialization process. For example,
repeated entities may be replaced with the object with the only "id" property, making the result JSON more
compact. See EntitySerializationOption
for details.
Additionally, an "_entityName" property is added to the JSON objects that represent an entity.
toJson
in interface EntitySerializationAPI
entity
- an entity to be serializedview
- a view that defines which entity properties should be added to the result JSON objectoptions
- options specifying how an entity should be serializedpublic java.lang.String toJson(java.util.Collection<? extends Entity> entities)
EntitySerializationAPI
EntitySerializationAPI.toJson(Collection, View, EntitySerializationOption...)
method with a null
view
parameter and with no serialization options.toJson
in interface EntitySerializationAPI
entities
- a collection of entities to be serializedpublic java.lang.String toJson(java.util.Collection<? extends Entity> entities, @Nullable View view, EntitySerializationOption... options)
EntitySerializationAPI
EntitySerializationAPI.toJson(Entity, View,
EntitySerializationOption...)
, but return a JSON array as a result.toJson
in interface EntitySerializationAPI
entities
- a list of entities to be serializedview
- a view that defines which entity properties should be added to the result JSON objectoptions
- options specifying how an entity should be serializedpublic java.lang.String objectToJson(java.lang.Object object, EntitySerializationOption... options)
EntitySerializationAPI
DateTimeDatatype
.objectToJson
in interface EntitySerializationAPI
object
- any POJO or collection of POJOsoptions
- options specifying how a JSON object graph for fields with type 'Entity' will be serializedpublic <T extends Entity> T entityFromJson(java.lang.String json, @Nullable com.haulmont.chile.core.model.MetaClass metaClass, EntitySerializationOption... options)
EntitySerializationAPI
The metaClass
parameter defines a result entity metaClass. It is optional. It must be defined if the JSON
object doesn't contain an "_entityName" property.
An entity may be serialized to the JSON in slightly different formats. The format is defined by the options
parameter. See EntitySerializationOption
for details.
entityFromJson
in interface EntitySerializationAPI
json
- a string that represents a JSON objectmetaClass
- a metaClass of the entity that will be createdoptions
- options specifying how a JSON object graph was serializedpublic <T extends Entity> java.util.Collection<T> entitiesCollectionFromJson(java.lang.String json, @Nullable com.haulmont.chile.core.model.MetaClass metaClass, EntitySerializationOption... options)
EntitySerializationAPI
entitiesCollectionFromJson
in interface EntitySerializationAPI
json
- a string that represents a JSON array of objectsmetaClass
- a metaClass of the entities that will be createdoptions
- options specifying how a JSON object graph was serializedpublic <T> T objectFromJson(java.lang.String json, java.lang.Class<T> clazz, EntitySerializationOption... options)
EntitySerializationAPI
DateTimeDatatype
format, entities object and fields of Entity type are
deserialized like in the EntitySerializationAPI.entityFromJson(String, MetaClass, EntitySerializationOption...)
methodobjectFromJson
in interface EntitySerializationAPI
json
- a string that represents an objectclazz
- java class of the objectoptions
- options specifying how a JSON object graph was serializedprotected com.google.gson.Gson createGsonForSerialization(@Nullable View view, EntitySerializationOption... options)
protected com.google.gson.Gson createGsonForDeserialization(@Nullable com.haulmont.chile.core.model.MetaClass metaClass, EntitySerializationOption... options)
@Nullable protected java.lang.reflect.Field getField(@Nullable java.lang.Class clazz, java.lang.String fieldName)
protected void makeFieldAccessible(java.lang.reflect.Field field)
protected boolean isCollectionDynamicAttribute(com.haulmont.chile.core.model.MetaProperty metaProperty)