Object Graph Mapper
The GenericObjectGraphMapper
class provides functionalities to map arbitrary Java objects to graph representations.
Overview
GenericObjectGraphMapper
leverages object-graph mappings to transform properties and relationships of an object into Nodes, Edges, and Attributes of a graph. This data modeling approach allows complex object-oriented structures to be represented as flexible and expressive graphs.
Core Components
-
ObjectGraphMapping: These strategies, with their various implementations such as LeafObjectGraphMapping, ListObjectGraphMapping, MapObjectGraphMapping, ObjectObjectGraphMapping, ReferenceObjectGraphMapping and InterfaceObjectGraphMapping, define how different types of objects are mapped to the graph.
-
Serialization: The mapping process can be guided by a specific "serialization type", an ID retrieved from the Schema, allowing for flexible mapping strategies based on the type of the object.
-
GraphMappingResult: This encapsulates the result of the object-to-graph mapping process, containing the resulting graph and elements that need to be removed from the previous state of the graph, aiding in keeping the graph's state updated with the object.
Method Overview
-
mapToGraph: This is the main method that takes an object and an
ObjectGraphMapping
, and converts the object into a graph representation. Based on tests, this method has shown a few behaviors:-
When provided with a
MissingFieldResolvingStrategy.LENIENT
strategy, it can gracefully handle missing fields by mapping what it can and ignoring the rest. -
It throws an error if an
ObjectGraphMapping
incorrectly describes an object or if an object that requires an identifying field is missing it. -
It throws an error if an object has multiple identifying fields.
-
It can correctly map objects to their respective graph nodes based on the IDs of the objects.
-
It can correctly map objects with multiple leaf nodes as well as object definitions that include multiple leaf nodes.
-
It can map lists as part of an object, correctly handling lists of objects and lists of primitive types.
-
-
resolveInternally: This method is used internally by
mapToGraph
to resolve the graph description for an object field, using a specific mapper that supports the givenObjectGraphMapping
.
This approach provides benefits such as:
-
Versatility: Complex object-oriented structures can be represented as expressive graphs.
-
Schema Evolution: By mapping with a serialization type, it's possible to evolve the schema over time without breaking existing mappings.
-
Object Querying: Data represented as a graph can be queried using graph algorithms, offering more powerful querying capabilities.
-
Data Integration: Data from different objects or systems can be integrated when represented as graphs.