Class DefaultInstanceBuilder
- All Implemented Interfaces:
InstanceBuilder
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultInstanceBuilder(TargetClassResolver classResolver, PendingReferenceRegistry pendingReferenceRegistry) DefaultInstanceBuilder(TargetClassResolver classResolver, PendingReferenceRegistry pendingReferenceRegistry, Map<String, Object> knownInstances) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNodeReference(String nodeId) Adds the specified value to the currently open collection.voidaddNodeReference(String property, String nodeId) Adds a reference to a node to the currently open object.voidAdds the specified value to the currently open collection.voidAdds the specified value of the specified property to the currently open object.voidCloses the most recently open collection.voidCloses 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.booleanChecks whether the current collection context represents aPropertiesattribute.booleanChecks whether the specified property is mapped to a plural field.booleanisPropertyDeserializable(String property) Checks whether the specified property can be deserialized.booleanisPropertyMapped(String property) Checks whether the specified property is mapped by the class representing the current instance context.voidopenCollection(CollectionType collectionType) Creates new instance of the specified collection type.voidopenCollection(String property) Creates new instance of appropriate collection and sets it as value of the specified property of the currently open object.<T> voidopenObject(String id, Class<T> cls) Creates new instance of the specified class.voidopenObject(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) -
DefaultInstanceBuilder
public DefaultInstanceBuilder(TargetClassResolver classResolver, PendingReferenceRegistry pendingReferenceRegistry, Map<String, Object> knownInstances)
-
-
Method Details
-
openObject
Description copied from interface:InstanceBuilderCreates 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:
openObjectin interfaceInstanceBuilder- Parameters:
id- Identifier of the object being openproperty- Property identifier (IRI)types- Types of the object being open
-
openObject
Description copied from interface:InstanceBuilderCreates 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:
openObjectin 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:InstanceBuilderCloses the most recently open object.- Specified by:
closeObjectin interfaceInstanceBuilder
-
openCollection
Description copied from interface:InstanceBuilderCreates 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:
openCollectionin interfaceInstanceBuilder- Parameters:
property- Property identifier (IRI)
-
openCollection
Description copied from interface:InstanceBuilderCreates 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:
openCollectionin interfaceInstanceBuilder- Parameters:
collectionType- Type of the JSON collection to instantiate in Java- See Also:
-
closeCollection
public void closeCollection()Description copied from interface:InstanceBuilderCloses the most recently open collection.- Specified by:
closeCollectionin interfaceInstanceBuilder
-
addValue
Description copied from interface:InstanceBuilderAdds 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:
addValuein interfaceInstanceBuilder- Parameters:
property- Property identifier (IRI)value- The value to set
-
addValue
Description copied from interface:InstanceBuilderAdds 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:
addValuein interfaceInstanceBuilder- Parameters:
value- The value to add
-
addNodeReference
Description copied from interface:InstanceBuilderAdds 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:
addNodeReferencein interfaceInstanceBuilder- Parameters:
property- Property identifier (IRI)nodeId- Identifier (IRI) of the node, i.e. value of the @id attribute
-
addNodeReference
Description copied from interface:InstanceBuilderAdds 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:
addNodeReferencein interfaceInstanceBuilder- Parameters:
nodeId- Identifier (IRI) of the node, i.e. value of the @id attribute
-
getCurrentRoot
Description copied from interface:InstanceBuilderReturns current root of the deserialized object graph.- Specified by:
getCurrentRootin interfaceInstanceBuilder- Returns:
- Object graph root, it can be a
OWLClassorJsonLdTypeinstance, or aCollection
-
getCurrentCollectionElementType
Description copied from interface:InstanceBuilderReturns the declared type of elements of the current instance, if it is a collection.- Specified by:
getCurrentCollectionElementTypein interfaceInstanceBuilder- Returns:
- Collection element type
-
isPlural
Description copied from interface:InstanceBuilderChecks 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
TypesandPropertiesfields are always treated as plural.- Specified by:
isPluralin interfaceInstanceBuilder- Parameters:
property- Property identifier (IRI)- Returns:
- Whether mapped field is collection-valued or not
-
isPropertyMapped
Description copied from interface:InstanceBuilderChecks whether the specified property is mapped by the class representing the current instance context.Returns true also for the
JsonLd.TYPEproperty, even though the target instance may not contain aTypesfield. The builder has to be able to handle types no matter whether a types field is present or not.- Specified by:
isPropertyMappedin interfaceInstanceBuilder- Parameters:
property- Property identifier (IRI)- Returns:
- Whether the property is mapped in the current instance context
-
isPropertyDeserializable
Description copied from interface:InstanceBuilderChecks 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:
isPropertyDeserializablein interfaceInstanceBuilder- Parameters:
property- Property identifier (IRI)- Returns:
- Whether property can be deserialized
- See Also:
-
getCurrentContextType
Description copied from interface:InstanceBuilderGets the Java type of the current object context.- Specified by:
getCurrentContextTypein interfaceInstanceBuilder- Returns:
- Java class of the instance currently being built
-
isCurrentCollectionProperties
public boolean isCurrentCollectionProperties()Description copied from interface:InstanceBuilderChecks whether the current collection context represents aPropertiesattribute.- Specified by:
isCurrentCollectionPropertiesin interfaceInstanceBuilder- Returns:
trueif the current context is a collection representing aPropertiesfield
-
getTargetType
Description copied from interface:InstanceBuilderGets 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:
getTargetTypein interfaceInstanceBuilder- Parameters:
property- Property whose target type to resolve- Returns:
- Target type wrapped in an optional
-