- All Implemented Interfaces:
org.neo4j.bolt.connection.values.Value,org.neo4j.driver.internal.AsValue,InternalValue,MapAccessor,MapAccessorWithDefaultValue,Value
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TMaps this value to the given type providing that is it supported.as(ParameterizedType type) asMap()Return the underlying map as a map of string keys and values converted usingValue.asObject().Return the underlying map as a map of string keys and values converted using the supplied function.asObject()This returns a java standard library representation of the underlying value, using a java type that is "sensible" given the underlying type.org.neo4j.bolt.connection.values.TypebooleancontainsKey(String key) Check if the list of keys contains the given keybooleanRetrieve the value of the property with the given keyinthashCode()booleanisEmpty()If this value represents a list or map, test if the collection is empty.keys()If the underlying value supportskey-based indexing, return an iterable of the keys in the map, this applies tomap,nodeandTypeSystem.RELATIONSHIP()relationship} values.intsize()If the underlying value is a collection type, return the number of values in the collection.toString()type()Returns the type of this value as defined in the Neo4j type system.values()Retrieve all values of the underlying collection<T> Iterable<T> Map and retrieve all values of the underlying collectionMethods inherited from class org.neo4j.driver.internal.value.ValueAdapter
asBoltVector, asBoolean, asBoolean, asByteArray, asByteArray, asDouble, asDouble, asEntity, asFloat, asFloat, asInt, asInt, asIsoDuration, asIsoDuration, asList, asList, asList, asList, asLocalDate, asLocalDate, asLocalDateTime, asLocalDateTime, asLocalTime, asLocalTime, asLong, asLong, asMap, asMap, asMapped, asNode, asNumber, asOffsetDateTime, asOffsetDateTime, asOffsetTime, asOffsetTime, asPath, asPoint, asPoint, asRelationship, asString, asString, asUnsupportedType, asValue, asVector, asZonedDateTime, asZonedDateTime, computeOrDefault, get, hasType, isFalse, isNull, isTrue, typeConstructorMethods inherited from class org.neo4j.driver.internal.types.InternalMapAccessorWithDefaultValue
get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, get, getMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.neo4j.driver.internal.value.InternalValue
as, asBoltIsoDuration, asBoltPoint, boltValues, getBoltValue
-
Constructor Details
-
MapValue
-
-
Method Details
-
isEmpty
public boolean isEmpty()Description copied from interface:ValueIf this value represents a list or map, test if the collection is empty.- Specified by:
isEmptyin interfaceorg.neo4j.bolt.connection.values.Value- Specified by:
isEmptyin interfaceValue- Overrides:
isEmptyin classValueAdapter- Returns:
trueif size() is 0, otherwisefalse
-
asObject
Description copied from interface:ValueThis returns a java standard library representation of the underlying value, using a java type that is "sensible" given the underlying type. The mapping for common types is as follows:TypeSystem.NULL()-nullTypeSystem.LIST()-ListTypeSystem.MAP()-MapTypeSystem.BOOLEAN()-BooleanTypeSystem.INTEGER()-LongTypeSystem.FLOAT()-DoubleTypeSystem.STRING()-StringTypeSystem.BYTES()- byte[]TypeSystem.DATE()-LocalDateTypeSystem.TIME()-OffsetTimeTypeSystem.LOCAL_TIME()-LocalTimeTypeSystem.DATE_TIME()-ZonedDateTimeTypeSystem.LOCAL_DATE_TIME()-LocalDateTimeTypeSystem.DURATION()-IsoDurationTypeSystem.POINT()-PointTypeSystem.NODE()-NodeTypeSystem.RELATIONSHIP()-RelationshipTypeSystem.PATH()-Path
Note that the types in
TypeSystemrefers to the Neo4j type system whereTypeSystem.INTEGER()andTypeSystem.FLOAT()are both 64-bit precision. This is why these types return javaLongandDouble, respectively.- Specified by:
asObjectin interfaceValue- Overrides:
asObjectin classValueAdapter- Returns:
- the value as a Java Object.
-
as
Description copied from interface:ValueMaps this value to the given type providing that is it supported.Basic Mapping
Supported destination types depend on the value
Type, please see the table below for more details.Object Mapping
Mapping of user-defined properties to user-defined types is supported for the following value types:
Example (using the Neo4j Movies Database):
// assuming the following Java record public record Movie(String title, String tagline, long released) {} // the nodes may be mapped to Movie instances var movies = driver.executableQuery("MATCH (movie:Movie) RETURN movie") .execute() .records() .stream() .map(record -> record.get("movie").as(Movie.class)) .toList();Note that Object Mapping is an alternative to accessing the user-defined values in a
MapAccessor. If Object Graph Mapping (OGM) is needed, please use a higher level solution built on top of the driver, like Spring Data Neo4j.The mapping is done by matching user-defined property names to target type constructor parameters. Therefore, the constructor parameters must either have
Propertyannotation or have a matching name that is available at runtime (note that the constructor parameter names are typically changed by the compiler unless either the compiler-parametersoption is used or they belong to the cannonical constructor ofjava.lang.Record). The name matching is case-sensitive.Additionally, the
Propertyannotation may be used when mapping a property with a different name tojava.lang.Recordcannonical constructor parameter.The constructor selection criteria is the following (top priority first):
- Maximum matching properties.
- Minimum mismatching properties.
Class.getDeclaredConstructors().Only constructors that are accessible or can be made accessible using
AccessibleObject.trySetAccessible()are included in the search. If multiple constructors have the same number of matching and mismatching properties, the first constructor that is accessible by default is selected.The search finishes as soon as a constructor that is accessible by default and matches all properties is found. Otherwise, it finishes once all constructors have been visited.
At least 1 property match must be present for mapping to work.
A
nullvalue is used for arguments that don't have a matching property. If the argument does not acceptnullvalue (this includes primitive types), an alternative constructor that excludes it must be available.The mapping only works for types with directly accessible constructors, not interfaces or abstract types.
Example with optional property (using the Neo4j Movies Database):
// assuming the following Java record public record Person(String name, long born) { // alternative constructor for values that don't have 'born' property available public Person(@Property("name") String name) { this(name, -1); } } // the nodes may be mapped to Person instances var persons = driver.executableQuery("MATCH (person:Person) RETURN person") .execute() .records() .stream() .map(record -> record.get("person").as(Person.class)) .toList();Types with generic parameters defined at the class level are not supported. However, constructor arguments with specific types are permitted.
Example (using the Neo4j Movies Database):
On the contrary, the following record would not be mapped because the type information is insufficient:// assuming the following Java record public record Acted(List<String> roles) {} // the relationships may be mapped to Acted instances var actedList = driver.executableQuery("MATCH ()-[acted:ACTED_IN]-() RETURN acted") .execute() .records() .stream() .map(record -> record.get("acted").as(Acted.class)) .toList();
Wildcard type value is not supported.public record Acted<T>(List<T> roles) {}- Type Parameters:
T- the target type to map to- Parameters:
targetClass- the target class to map to- Returns:
- the mapped value
- See Also:
-
as
-
asMap
Description copied from interface:MapAccessorReturn the underlying map as a map of string keys and values converted usingValue.asObject().This is equivalent to calling
MapAccessor.asMap(Function)withValues.ofObject().- Specified by:
asMapin interfaceMapAccessor- Overrides:
asMapin classValueAdapter- Returns:
- the value as a Java map
-
asMap
Description copied from interface:MapAccessorReturn the underlying map as a map of string keys and values converted using the supplied function.- Specified by:
asMapin interfaceMapAccessor- Overrides:
asMapin classValueAdapter- Type Parameters:
T- the type of map values- Parameters:
mapFunction- a function to map from Value to T. SeeValuesfor some predefined functions, such asValues.ofBoolean(),Values.ofList(Function).- Returns:
- the value as a map from string keys to values of type T obtained from mapping the original map values, if possible
- See Also:
-
size
public int size()Description copied from interface:ValueIf the underlying value is a collection type, return the number of values in the collection.For
TypeSystem.LIST()list} values, this will return the size of the list.For
mapvalues, this will return the number of entries in the map.For
nodeandTypeSystem.RELATIONSHIP()relationship} values, this will return the number of properties.For
pathvalues, this returns the length (number of relationships) in the path.- Specified by:
sizein interfaceMapAccessor- Specified by:
sizein interfaceValue- Overrides:
sizein classValueAdapter- Returns:
- the number of values in an underlying collection
-
containsKey
Description copied from interface:MapAccessorCheck if the list of keys contains the given key- Specified by:
containsKeyin interfaceMapAccessor- Overrides:
containsKeyin classValueAdapter- Parameters:
key- the key- Returns:
trueif this map keys contains the given key otherwisefalse
-
keys
Description copied from interface:ValueIf the underlying value supportskey-based indexing, return an iterable of the keys in the map, this applies tomap,nodeandTypeSystem.RELATIONSHIP()relationship} values.- Specified by:
keysin interfaceMapAccessor- Specified by:
keysin interfaceValue- Overrides:
keysin classValueAdapter- Returns:
- the keys in the value
-
values
Description copied from interface:MapAccessorRetrieve all values of the underlying collection- Specified by:
valuesin interfaceMapAccessor- Overrides:
valuesin classValueAdapter- Returns:
- all values in unspecified order
-
values
Description copied from interface:MapAccessorMap and retrieve all values of the underlying collection- Specified by:
valuesin interfaceMapAccessor- Overrides:
valuesin classValueAdapter- Type Parameters:
T- the target type of mapping- Parameters:
mapFunction- a function to map from Value to T. SeeValuesfor some predefined functions, such asValues.ofBoolean(),Values.ofList(Function).- Returns:
- the result of mapping all values in unspecified order
-
get
Description copied from interface:MapAccessorRetrieve the value of the property with the given key- Specified by:
getin interfaceMapAccessor- Overrides:
getin classValueAdapter- Parameters:
key- the key of the property- Returns:
- the property's value or a
NullValueif no such key exists
-
toString
- Specified by:
toStringin interfaceValue- Specified by:
toStringin classValueAdapter
-
type
Description copied from interface:ValueReturns the type of this value as defined in the Neo4j type system.- Returns:
- the type of this value as defined in the Neo4j type system
-
boltValueType
public org.neo4j.bolt.connection.values.Type boltValueType() -
asBoltMap
-
equals
- Specified by:
equalsin interfaceValue- Specified by:
equalsin classValueAdapter
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceValue- Specified by:
hashCodein classValueAdapter
-