Class TimeValue

All Implemented Interfaces:
org.neo4j.driver.internal.AsValue, InternalValue, MapAccessor, MapAccessorWithDefaultValue, Value

public class TimeValue extends ObjectValueAdapter<OffsetTime>
  • Constructor Details

  • Method Details

    • asOffsetTime

      public OffsetTime asOffsetTime()
      Specified by:
      asOffsetTime in interface Value
      Overrides:
      asOffsetTime in class ValueAdapter
      Returns:
      the value as a OffsetTime, if possible.
    • type

      public Type type()
      Returns:
      The type of this value as defined in the Neo4j type system
    • asBoltValue

      public BoltValue asBoltValue()
    • as

      public <T> T as(Class<T> targetClass)
      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.

      Supported Mappings
      Value Type Supported Target Types
      TypeSystem.BOOLEAN() boolean, Boolean
      TypeSystem.BYTES() byte[]
      TypeSystem.STRING() String, char, Character
      TypeSystem.INTEGER() long, Long, int, Integer, short, Short, double, Double, float, Float
      TypeSystem.FLOAT() long, Long, int, Integer, double, Double, float, Float
      TypeSystem.PATH() Path
      TypeSystem.POINT() Point
      TypeSystem.DATE() LocalDate
      TypeSystem.TIME() OffsetTime
      TypeSystem.LOCAL_TIME() LocalTime
      TypeSystem.LOCAL_DATE_TIME() LocalDateTime
      TypeSystem.DATE_TIME() ZonedDateTime, OffsetDateTime
      TypeSystem.DURATION() IsoDuration, Period (only when seconds = 0 and nanoseconds = 0 and no overflow happens), Duration (only when months = 0 and days = 0 and no overflow happens)
      TypeSystem.NULL() null
      TypeSystem.LIST() List, T[] as long as list elements may be mapped to the array component type (for example, char[], boolean[], String[], long[], int[], short[], double[], float[])
      TypeSystem.MAP() Map
      TypeSystem.NODE() Node
      TypeSystem.RELATIONSHIP() Relationship

      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 of java.lang.Record). The name matching is case-sensitive.

      Additionally, the Property annotation may be used when mapping a property with a different name to java.lang.Record cannonical constructor parameter.

      The constructor selection criteria is the following (top priority first):

      1. Maximum matching properties.
      2. Minimum mismatching properties.
      The constructor search is done in the order defined by the 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 accept null 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();
       
       
      On the contrary, the following record would not be mapped because the type information is insufficient:
       
       public record Acted<T>(List<T> roles) {}
       
       
      Wildcard type value is not supported.
      Type Parameters:
      T - the target type to map to
      Parameters:
      targetClass - the target class to map to
      Returns:
      the mapped value
      See Also: