Class DefaultInstanceBuilder
- All Implemented Interfaces:
InstanceBuilder
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultInstanceBuilder
(TargetClassResolver classResolver, PendingReferenceRegistry pendingReferenceRegistry) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNodeReference
(String nodeId) Adds the specified value to the currently open collection.void
addNodeReference
(String property, String nodeId) Adds a reference to a node to the currently open object.void
Adds the specified value to the currently open collection.void
Adds the specified value of the specified property to the currently open object.void
Closes the most recently open collection.void
Closes the most recently open object.Class<?>
Returns the declared type of elements of the current instance, if it is a collection.Class<?>
Gets the Java type of the current object context.Returns current root of the deserialized object graph.Class<?>
getTargetType
(String property) Gets the target type of the specified property.boolean
Checks whether the current collection context represents aProperties
attribute.boolean
Checks whether the specified property is mapped to a plural field.boolean
isPropertyDeserializable
(String property) Checks whether the specified property can be deserialized.boolean
isPropertyMapped
(String property) Checks whether the specified property is mapped by the class representing the current instance context.void
openCollection
(CollectionType collectionType) Creates new instance of the specified collection type.void
openCollection
(String property) Creates new instance of appropriate collection and sets it as value of the specified property of the currently open object.<T> void
openObject
(String id, Class<T> cls) Creates new instance of the specified class.void
openObject
(String id, String property, List<String> types) Creates new instance to fill filled mapped by the specified property.
-
Constructor Details
-
DefaultInstanceBuilder
public DefaultInstanceBuilder(TargetClassResolver classResolver, PendingReferenceRegistry pendingReferenceRegistry)
-
-
Method Details
-
openObject
Description copied from interface:InstanceBuilder
Creates new instance to fill filled mapped by the specified property.The instance type is determined from the declared type of the mapped field, which is taken from the currently open object, and from the specified types. Therefore, another object has to be already open before this method can be called.
The new instance also becomes the currently open object.
This method should also verify cardinality, i.e. multiple objects cannot be set for the same property, if the field it maps to is singular.
This method assumes that the property is mapped, i.e. that
InstanceBuilder.isPropertyMapped(String)
returned true.- Specified by:
openObject
in interfaceInstanceBuilder
- Parameters:
id
- Identifier of the object being openproperty
- Property identifier (IRI)types
- Types of the object being open
-
openObject
Description copied from interface:InstanceBuilder
Creates new instance of the specified class.If there is a collection currently open, it adds the new instance to it.
The new instance also becomes the currently open object.
This method is intended for creating top level objects or adding objects to collections. Use
InstanceBuilder.openObject(String, String, List)
for opening objects as values of attributes.- Specified by:
openObject
in interfaceInstanceBuilder
- Type Parameters:
T
- The type of the object to open- Parameters:
id
- Identifier of the object being opencls
- Java type of the object being open- See Also:
-
closeObject
public void closeObject()Description copied from interface:InstanceBuilder
Closes the most recently open object.- Specified by:
closeObject
in interfaceInstanceBuilder
-
openCollection
Description copied from interface:InstanceBuilder
Creates new instance of appropriate collection and sets it as value of the specified property of the currently open object.The collection type is determined from the declared type of the mapped field, which is taken from the currently open object. Therefore, another object has to be already open before this method can be called.
The new collection also becomes the currently open object.
This method should also verify cardinality, i.e. a collection cannot be set as value of a field mapped by
property
, if the field is singular.This method assumes that the property is mapped, i.e. that
InstanceBuilder.isPropertyMapped(String)
returned true.- Specified by:
openCollection
in interfaceInstanceBuilder
- Parameters:
property
- Property identifier (IRI)
-
openCollection
Description copied from interface:InstanceBuilder
Creates new instance of the specified collection type.If there is a collection currently open, it adds the new collection as its new item.
The new collection also becomes the currently open object.
This method is intended for creating top level collections or nesting collections. Use
InstanceBuilder.openCollection(String)
for opening collections as values of attributes.- Specified by:
openCollection
in interfaceInstanceBuilder
- Parameters:
collectionType
- Type of the JSON collection to instantiate in Java- See Also:
-
closeCollection
public void closeCollection()Description copied from interface:InstanceBuilder
Closes the most recently open collection.- Specified by:
closeCollection
in interfaceInstanceBuilder
-
addValue
Description copied from interface:InstanceBuilder
Adds the specified value of the specified property to the currently open object.This method is intended for non-composite JSON values like String, Number Boolean and
null
. It can also handle IRIs of objects already parsed by the deserializer, which are serialized as Strings in JSON-LD. In this case, the field is filled with the deserialized object.This method should also verify cardinality and correct typing, e.g. multiple values cannot be set for the same property, if the field it maps to is singular.
This method assumes that the property is mapped, i.e. that
InstanceBuilder.isPropertyMapped(String)
returned true.- Specified by:
addValue
in interfaceInstanceBuilder
- Parameters:
property
- Property identifier (IRI)value
- The value to set
-
addValue
Description copied from interface:InstanceBuilder
Adds the specified value to the currently open collection.This method is intended for non-composite JSON values like String, Number Boolean and
null
. It can also handle IRIs of objects already parsed by the deserializer, which are serialized as Strings in JSON-LD. In this case, the deserialized object is added to the collection.- Specified by:
addValue
in interfaceInstanceBuilder
- Parameters:
value
- The value to add
-
addNodeReference
Description copied from interface:InstanceBuilder
Adds a reference to a node to the currently open object.This methods is invoked in case the deserializer encounters an object with a single attribute - @id. This assumes that the node either references an already encountered object (known instance) or that the node is a value of a plain identifier-valued object property.
This method should also verify cardinality and correct typing, e.g. multiple values cannot be set for the same property, if the field it maps to is singular.
It is assumed that the property is mapped, i.e. that
InstanceBuilder.isPropertyMapped(String)
returned true.- Specified by:
addNodeReference
in interfaceInstanceBuilder
- Parameters:
property
- Property identifier (IRI)nodeId
- Identifier (IRI) of the node, i.e. value of the @id attribute
-
addNodeReference
Description copied from interface:InstanceBuilder
Adds the specified value to the currently open collection.This methods is invoked in case the deserializer encounters an object with a single attribute - @id. This assumes that the node either references an already encountered object (known instance) or that the node is a value of a plain identifier-valued object property.
- Specified by:
addNodeReference
in interfaceInstanceBuilder
- Parameters:
nodeId
- Identifier (IRI) of the node, i.e. value of the @id attribute
-
getCurrentRoot
Description copied from interface:InstanceBuilder
Returns current root of the deserialized object graph.- Specified by:
getCurrentRoot
in interfaceInstanceBuilder
- Returns:
- Object graph root, it can be a
OWLClass
instance, or aCollection
-
getCurrentCollectionElementType
Description copied from interface:InstanceBuilder
Returns the declared type of elements of the current instance, if it is a collection.- Specified by:
getCurrentCollectionElementType
in interfaceInstanceBuilder
- Returns:
- Collection element type
-
isPlural
Description copied from interface:InstanceBuilder
Checks whether the specified property is mapped to a plural field.This method assumes that the property is mapped, i.e. that
InstanceBuilder.isPropertyMapped(String)
returned true.Note that
Types
andProperties
fields are always treated as plural.- Specified by:
isPlural
in interfaceInstanceBuilder
- Parameters:
property
- Property identifier (IRI)- Returns:
- Whether mapped field is collection-valued or not
-
isPropertyMapped
Description copied from interface:InstanceBuilder
Checks whether the specified property is mapped by the class representing the current instance context.Returns true also for the
JsonLd.TYPE
property, even though the target instance may not contain aTypes
field. The builder has to be able to handle types no matter whether a types field is present or not.- Specified by:
isPropertyMapped
in interfaceInstanceBuilder
- Parameters:
property
- Property identifier (IRI)- Returns:
- Whether the property is mapped in the current instance context
-
isPropertyDeserializable
Description copied from interface:InstanceBuilder
Checks whether the specified property can be deserialized.A property cannot be deserialized if it is not mapped or if the mapped field's access is read-only.
- Specified by:
isPropertyDeserializable
in interfaceInstanceBuilder
- Parameters:
property
- Property identifier (IRI)- Returns:
- Whether property can be deserialized
- See Also:
-
getCurrentContextType
Description copied from interface:InstanceBuilder
Gets the Java type of the current object context.- Specified by:
getCurrentContextType
in interfaceInstanceBuilder
- Returns:
- Java class of the instance currently being built
-
isCurrentCollectionProperties
public boolean isCurrentCollectionProperties()Description copied from interface:InstanceBuilder
Checks whether the current collection context represents aProperties
attribute.- Specified by:
isCurrentCollectionProperties
in interfaceInstanceBuilder
- Returns:
true
if the current context is a collection representing aProperties
field
-
getTargetType
Description copied from interface:InstanceBuilder
Gets the target type of the specified property.That is, it retrieves the type of the field to which the specified property is mapped. If the target field is a collection, the element type is returned (equivalent to
InstanceBuilder.getCurrentCollectionElementType()
).This method assumes that the property is mapped, i.e. that
InstanceBuilder.isPropertyMapped(String)
returned true.- Specified by:
getTargetType
in interfaceInstanceBuilder
- Parameters:
property
- Property whose target type to resolve- Returns:
- Target type wrapped in an optional
-