- All Implemented Interfaces:
org.neo4j.driver.internal.AsValue
,InternalValue
,MapAccessor
,MapAccessorWithDefaultValue
,Value
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
Maps this value to the given type providing that is it supported.byte[]
byte[]
asObject()
This returns a java standard library representation of the underlying value, using a java type that is "sensible" given the underlying type.boolean
int
hashCode()
boolean
isEmpty()
If this value represents a list or map, test if the collection is empty.int
size()
If the underlying value is a collection type, return the number of values in the collection.toString()
type()
Methods inherited from class org.neo4j.driver.internal.value.ValueAdapter
asBoolean, asBoolean, asByteArray, asDouble, asDouble, asEntity, asFloat, asFloat, asInt, asInt, asIsoDuration, asIsoDuration, asList, asList, asList, asList, asLocalDate, asLocalDate, asLocalDateTime, asLocalDateTime, asLocalTime, asLocalTime, asLong, asLong, asMap, asMap, asMap, asMap, asMapped, asNode, asNumber, asOffsetDateTime, asOffsetDateTime, asOffsetTime, asOffsetTime, asPath, asPoint, asPoint, asRelationship, asString, asString, asValue, asZonedDateTime, asZonedDateTime, computeOrDefault, containsKey, get, get, hasType, isFalse, isNull, isTrue, keys, typeConstructor, values, values
Methods 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, get
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.neo4j.driver.internal.value.InternalValue
as, as
-
Constructor Details
-
BytesValue
public BytesValue(byte[] val)
-
-
Method Details
-
isEmpty
public boolean isEmpty()Description copied from interface:Value
If this value represents a list or map, test if the collection is empty.- Specified by:
isEmpty
in interfaceValue
- Overrides:
isEmpty
in classValueAdapter
- Returns:
true
if size() is 0, otherwisefalse
-
size
public int size()Description copied from interface:Value
If 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
map
values, this will return the number of entries in the map.For
node
andTypeSystem.RELATIONSHIP()
relationship} values, this will return the number of properties.For
path
values, this returns the length (number of relationships) in the path.- Specified by:
size
in interfaceMapAccessor
- Specified by:
size
in interfaceValue
- Overrides:
size
in classValueAdapter
- Returns:
- the number of values in an underlying collection
-
asObject
public byte[] asObject()Description copied from interface:Value
This 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()
-null
TypeSystem.LIST()
-List
TypeSystem.MAP()
-Map
TypeSystem.BOOLEAN()
-Boolean
TypeSystem.INTEGER()
-Long
TypeSystem.FLOAT()
-Double
TypeSystem.STRING()
-String
TypeSystem.BYTES()
- byte[]TypeSystem.DATE()
-LocalDate
TypeSystem.TIME()
-OffsetTime
TypeSystem.LOCAL_TIME()
-LocalTime
TypeSystem.DATE_TIME()
-ZonedDateTime
TypeSystem.LOCAL_DATE_TIME()
-LocalDateTime
TypeSystem.DURATION()
-IsoDuration
TypeSystem.POINT()
-Point
TypeSystem.NODE()
-Node
TypeSystem.RELATIONSHIP()
-Relationship
TypeSystem.PATH()
-Path
Note that the types in
TypeSystem
refers to the Neo4j type system whereTypeSystem.INTEGER()
andTypeSystem.FLOAT()
are both 64-bit precision. This is why these types return javaLong
andDouble
, respectively.- Specified by:
asObject
in interfaceValue
- Overrides:
asObject
in classValueAdapter
- Returns:
- the value as a Java Object.
-
asByteArray
public byte[] asByteArray()- Specified by:
asByteArray
in interfaceValue
- Overrides:
asByteArray
in classValueAdapter
- Returns:
- the value as a Java byte array, if possible.
-
as
Description copied from interface:Value
Maps 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
Property
annotation 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-parameters
option is used or they belong to the cannonical constructor ofjava.lang.Record
). The name matching is case-sensitive.Additionally, the
Property
annotation may be used when mapping a property with a different name tojava.lang.Record
cannonical constructor parameter.The constructor selection criteria is the following (top priority first):
- Maximum matching properties.
- Minimum mismatching properties.
Class.getDeclaredConstructors()
and is finished either when a full match is found with no mismatches or once all constructors have been visited.At least 1 property match must be present for mapping to work.
A
null
value is used for arguments that don't have a matching property. If the argument does not acceptnull
value (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):
// 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();
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:
-
type
- Returns:
- The type of this value as defined in the Neo4j type system
-
equals
- Specified by:
equals
in interfaceValue
- Specified by:
equals
in classValueAdapter
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceValue
- Specified by:
hashCode
in classValueAdapter
-
toString
- Specified by:
toString
in interfaceValue
- Specified by:
toString
in classValueAdapter
-
asBoltValue
-