Fixed malformed-number parsing (#31) and added java.time mapper support (#23)#32
Open
Kitty-Hivens wants to merge 2 commits into
Open
Fixed malformed-number parsing (#31) and added java.time mapper support (#23)#32Kitty-Hivens wants to merge 2 commits into
Kitty-Hivens wants to merge 2 commits into
Conversation
… parser (JavaWebStack#31) parseNumber now validates the candidate token without consuming it and returns null on failure, so the existing error path reports a proper ParseException at the offending position instead of leaking a NumberFormatException. Also fixed exponent-only numbers (e.g. 1e3) being routed to Long.parseLong and failing.
New JavaTimeMapper handles LocalDate, LocalDateTime, LocalTime, Instant, OffsetDateTime, ZonedDateTime, OffsetTime, Year, YearMonth and MonthDay. Values serialize to their canonical ISO-8601 form by default; @DateFormat still applies -- a custom pattern (DateTimeFormatter syntax) or epoch mode (Instant only, otherwise a MapperException). Registered as a sibling of DateMapper, no public API or Java language level change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR bundles two independent changes.
JSON parser: malformed numbers (#31)
parseNumbernow validates the candidate token without consuming it and returnsnullon failure, so the existing error path reports a properParseExceptionat the offending position instead of leaking aNumberFormatException. Exponent-only numbers (e.g.1e3), previously routed toLong.parseLongand failing, now parse as doubles.Mapper: java.time support (#23)
A new
JavaTimeMapper(sibling ofDateMapper, registered inDefaultMappers) maps the corejava.timetypes:LocalDate,LocalDateTime,LocalTime,Instant,OffsetDateTime,ZonedDateTime,OffsetTime,Year,YearMonth,MonthDay. Values serialize to their canonical ISO-8601 form by default. The existing@DateFormatannotation still applies: a custom pattern usesDateTimeFormattersyntax, and epoch mode is supported forInstantonly (any other type throws aMapperExceptionrather than silently dropping the zone/offset). No public API or Java language level change (target stays 8).Out of scope, as separate follow-ups:
Duration/Period/ZoneId/ZoneOffset, andjava.timesupport in the BSON converter.Test plan
mvn testgreen.JsonParserTest: added malformed-number cases (--,-,1.2.3,12e,.) assertingParseException, plus scientific notation (1e3,2.5E-2).JavaTimeMapperTest: ISO round-trip for all 10 types, epochInstant(seconds/millis), custom pattern, epoch rejection on a non-Instanttype, and malformed input ->MapperException.