Class EntitySerializationImpl
- All Implemented Interfaces:
EntitySerialization
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected classprotected classprotected static classClass is used for storing a collection of entities already processed during the serialization.protected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AccessManagerprotected CorePropertiesprotected DatatypeRegistryprotected EntityStatesprotected Metadataprotected MetadataToolsprotected EntitySerializationTokenManagerFields inherited from interface io.jmix.core.EntitySerialization
ENTITY_NAME_PROP, INSTANCE_NAME_PROP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.google.gson.GsoncreateGsonForDeserialization(MetaClass metaClass, EntitySerializationOption... options) protected com.google.gson.GsoncreateGsonForSerialization(FetchPlan fetchPlan, EntitySerializationOption... options) <T> Collection<T>entitiesCollectionFromJson(String json, MetaClass metaClass, EntitySerializationOption... options) Deserializes a JSON array of objects to entities collection<T> TentityFromJson(String json, MetaClass metaClass, EntitySerializationOption... options) Deserializes a JSON object to the entity.protected Fieldprotected voidmakeFieldAccessible(Field field) <T> TobjectFromJson(String json, Type type, EntitySerializationOption... options) Deserializes an object of any class from JSON.objectToJson(Object object, EntitySerializationOption... options) Serializes any custom POJO or collection of POJOs or JSON.An overloaded version of theEntitySerialization.toJson(Object, FetchPlan, EntitySerializationOption...)method with a nullfetchPlanparameter and with no serialization options.toJson(Object entity, FetchPlan fetchPlan, EntitySerializationOption... options) Serializes a single entity to the JSON object graph.toJson(Collection<?> entities) An overloaded version of theEntitySerialization.toJson(Collection, FetchPlan, EntitySerializationOption...)method with a nullfetchPlanparameter and with no serialization options.toJson(Collection<?> entities, FetchPlan fetchPlan, EntitySerializationOption... options) Serializes a collection of entities to the JSON array.
-
Field Details
-
metadataTools
-
metadata
-
accessManager
-
entityStates
-
datatypeRegistry
-
tokenManager
-
coreProperties
-
extensionResolver
-
context
-
-
Constructor Details
-
EntitySerializationImpl
public EntitySerializationImpl()
-
-
Method Details
-
toJson
Description copied from interface:EntitySerializationAn overloaded version of theEntitySerialization.toJson(Object, FetchPlan, EntitySerializationOption...)method with a nullfetchPlanparameter and with no serialization options.- Specified by:
toJsonin interfaceEntitySerialization- Parameters:
entity- an entity to be serialized- Returns:
- a string that represents a JSON object
-
toJson
public String toJson(Object entity, @Nullable FetchPlan fetchPlan, EntitySerializationOption... options) Description copied from interface:EntitySerializationSerializes a single entity to the JSON object graph.If the
fetchPlanparameter is null then all loaded entity properties will be presented in JSON, otherwise only loaded properties that are in the fetchPlan will be in the JSON object.The
optionsparameter 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. SeeEntitySerializationOptionfor details.Additionally, an "_entityName" property is added to the JSON objects that represent an entity.
- Specified by:
toJsonin interfaceEntitySerialization- Parameters:
entity- an entity to be serializedfetchPlan- a fetch plan that defines which entity properties should be added to the result JSON objectoptions- options specifying how an entity should be serialized- Returns:
- a string that represents a JSON object
-
toJson
Description copied from interface:EntitySerializationAn overloaded version of theEntitySerialization.toJson(Collection, FetchPlan, EntitySerializationOption...)method with a nullfetchPlanparameter and with no serialization options.- Specified by:
toJsonin interfaceEntitySerialization- Parameters:
entities- a collection of entities to be serialized- Returns:
- a string that represent a JSON array which contains entity objects
-
toJson
public String toJson(Collection<?> entities, @Nullable FetchPlan fetchPlan, EntitySerializationOption... options) Description copied from interface:EntitySerializationSerializes a collection of entities to the JSON array. Method works like theEntitySerialization.toJson(Object, FetchPlan, EntitySerializationOption...), but return a JSON array as a result.- Specified by:
toJsonin interfaceEntitySerialization- Parameters:
entities- a list of entities to be serializedfetchPlan- a fetch plan that defines which entity properties should be added to the result JSON objectoptions- options specifying how an entity should be serialized- Returns:
- a string that represents a JSON array of objects.
-
objectToJson
Description copied from interface:EntitySerializationSerializes any custom POJO or collection of POJOs or JSON. If some field in POJO is an entity then this field will be serialized according to entity serialization rules. Date fields are serialized according to the format of theDateTimeDatatype.- Specified by:
objectToJsonin interfaceEntitySerialization- Parameters:
object- any POJO or collection of POJOsoptions- options specifying how a JSON object graph for fields with type 'Entity' will be serialized- Returns:
- a string that represents a JSON object or JSON array
-
entityFromJson
public <T> T entityFromJson(String json, @Nullable MetaClass metaClass, EntitySerializationOption... options) Description copied from interface:EntitySerializationDeserializes a JSON object to the entity.The
metaClassparameter 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
optionsparameter. SeeEntitySerializationOptionfor details.- Specified by:
entityFromJsonin interfaceEntitySerialization- Parameters:
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 serialized- Returns:
- an entity
-
entitiesCollectionFromJson
public <T> Collection<T> entitiesCollectionFromJson(String json, @Nullable MetaClass metaClass, EntitySerializationOption... options) Description copied from interface:EntitySerializationDeserializes a JSON array of objects to entities collection- Specified by:
entitiesCollectionFromJsonin interfaceEntitySerialization- Parameters:
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 serialized- Returns:
- an entities collection
-
objectFromJson
Description copied from interface:EntitySerializationDeserializes an object of any class from JSON. Date fields are deserialized according to theDateTimeDatatypeformat, entities object and fields of Entity type are deserialized like in theEntitySerialization.entityFromJson(String, MetaClass, EntitySerializationOption...)method- Specified by:
objectFromJsonin interfaceEntitySerialization- Parameters:
json- a string that represents an objecttype- type of the objectoptions- options specifying how a JSON object graph was serialized- Returns:
- deserialized object
-
createGsonForSerialization
protected com.google.gson.Gson createGsonForSerialization(@Nullable FetchPlan fetchPlan, EntitySerializationOption... options) -
createGsonForDeserialization
protected com.google.gson.Gson createGsonForDeserialization(@Nullable MetaClass metaClass, EntitySerializationOption... options) -
getField
-
makeFieldAccessible
-