-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InstantDeserializer
fails to parse negative numeric timestamp strings for pre-1970 values
#291
Comments
I think I'd be open to accepting a PR, if you think you could provide one? I agree that it is an edge case, but if special handling would help and would not break main use case, that sounds like a reasonable improvement to me. |
In absence of fix, even PR for reproduction would be useful. |
Full Issue Title: InstantDeserializer fails to parse negative numeric timestamp strings for pre-1970 values. - Updated `InstantDeserializer._countPeriods(String)` to check for `-` and `+` at beginning of numeric string. - Additionally, added check if `ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` is enabled. If disabled, Throws same exception as before change from `_countPeriods(...)`. - Moved associated tests out of `tofix` directory
Full Issue Title: InstantDeserializer fails to parse negative numeric timestamp strings for pre-1970 values. - Updated `InstantDeserializer._countPeriods(String)` to check for `-` and `+` at beginning of numeric string. - Additionally, added check if `ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` is enabled. If disabled, Throws same exception as before change from `_countPeriods(...)`. - Moved associated tests out of `failed` directory
Full Issue Title: InstantDeserializer fails to parse negative numeric timestamp strings for pre-1970 values. - Updated `InstantDeserializer._countPeriods(String)` to check for `-` and `+` at beginning of numeric string. - Additionally, added check if `ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` is enabled. If disabled, throws same exception as before change from `_countPeriods(...)`. - Moved associated tests out of `failed` directory
Full Issue Title: InstantDeserializer fails to parse negative numeric timestamp strings for pre-1970 values. - Updated `InstantDeserializer._countPeriods(String)` to check for `-` and `+` at beginning of numeric string. - Additionally, added check if `ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` is enabled. If disabled, throws same exception as before change from `_countPeriods(...)`. - Moved associated tests out of `failed` directory
Full Issue Title: InstantDeserializer fails to parse negative numeric timestamp strings for pre-1970 values. - Updated `InstantDeserializer._countPeriods(String)` to check for `-` and `+` at beginning of numeric string. - Additionally, added check if `ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` is enabled. If disabled, throws same exception as before change from `_countPeriods(...)`. - Moved associated tests out of `failing` directory
Changed the function signature of `_countPeriods(JsonParser, String)` to `_countPeriods(String, boolean)` per suggestion from user cowtowncoder
InstantDeserializer
fails to parse negative numeric timestamp strings for pre-1970 values
…amp strings for pre-1970 values (#362)
Fixed via #362 for 2.18.4 |
Encountered while debugging through a project making use of this for Avro serialization/deserialization:
For an object containing a java.time.Instant with associated Avro schema field of "type" : [ "null", { "type" : "string", "java-class" : "java.time.Instant"} ] ...
InstantDeserializer._fromString() is used to try and parse these numeric timestamp strings, but its _countPeriods() helper method does not account for the possible leading '-' character
https://github.com/FasterXML/jackson-modules-java8/blob/2.16/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java#L369-L384
This causes _fromString() to skip over the parsing method that would work in this situation ...
https://github.com/FasterXML/jackson-modules-java8/blob/2.16/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java#L409-L410
... and instead fall through into DateTimeFormatter, which cannot handle this type of string and throws a DateTimeParseException
https://github.com/FasterXML/jackson-modules-java8/blob/2.16/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java#L433
Example code:
Output:
I realize this example may be somewhat of an edge case (if not an outdated, deprecated, and/or ill-advised one), given the documentation's current directions towards the use of AvroJavaTimeModule and a schema using numeric data types for java time classes (which does work), but figured this might be worth logging just in case there might be other means of encountering this problem.
For whatever it may be worth, configuring WRITE_DATES_AS_TIMESTAMPS=false appears to provide a workaround (for newly-serialized data, at least), should one's Avro schema not be easily changeable.
The text was updated successfully, but these errors were encountered: