Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-16260

Handle JSR310 Date classes in JavaBinCodec

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Patch Available
    • Minor
    • Resolution: Unresolved
    • 9.0, 8.11.1
    • None
    • clients - java
    • None

    Description

      JavaBinCodec currently only supports java.util.Date as Date input and doesn't handle JSR310 classes like Instant or LocalDate. As a result adding a SolrInputDocument which contains a LocalDate will be serialized in SolrJ as java.time.LocalDate:2022-12-31 using the fallback logic in JavaBinCodec#writeVal. This value then gets parsed on the server and throws an exception if the field is defined as a date field in the schema.

      I've written a small PR on Github to support ZonedDateTime, LocalDate and Instant as variants of Date (all get stored in Javabin as epoch millis and converted to Date on deserializing). I've not added support for LocalDateTime since it lacks enough information to be converted to epoch millis, but maybe there should be some warning or error provided to show that it isn't supported by SolrJ (instead of the generic "Couldn't parse date because: Improperly formatted datetime:" Exception)

       

      Note: A user could provide the value either as String (e.g. using Instant#toString) or ObjectResolver, which gets parsed correctly, but compared to the handling of java.util.Date that's not very intuitive.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              sgift Sebastian Gift
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h