Skip to content

Fixed malformed-number parsing (#31) and added java.time mapper support (#23)#32

Open
Kitty-Hivens wants to merge 2 commits into
JavaWebStack:devfrom
Kitty-Hivens:dev
Open

Fixed malformed-number parsing (#31) and added java.time mapper support (#23)#32
Kitty-Hivens wants to merge 2 commits into
JavaWebStack:devfrom
Kitty-Hivens:dev

Conversation

@Kitty-Hivens

@Kitty-Hivens Kitty-Hivens commented Jun 9, 2026

Copy link
Copy Markdown

This PR bundles two independent changes.

JSON parser: malformed numbers (#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. Exponent-only numbers (e.g. 1e3), previously routed to Long.parseLong and failing, now parse as doubles.

Mapper: java.time support (#23)

A new JavaTimeMapper (sibling of DateMapper, registered in DefaultMappers) maps the core java.time types: LocalDate, LocalDateTime, LocalTime, Instant, OffsetDateTime, ZonedDateTime, OffsetTime, Year, YearMonth, MonthDay. Values serialize to their canonical ISO-8601 form by default. The existing @DateFormat annotation still applies: a custom pattern uses DateTimeFormatter syntax, and epoch mode is supported for Instant only (any other type throws a MapperException rather 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, and java.time support in the BSON converter.

Test plan

  • mvn test green.
  • JsonParserTest: added malformed-number cases (--, -, 1.2.3, 12e, .) asserting ParseException, plus scientific notation (1e3, 2.5E-2).
  • JavaTimeMapperTest: ISO round-trip for all 10 types, epoch Instant (seconds/millis), custom pattern, epoch rejection on a non-Instant type, and malformed input -> MapperException.

… 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.
@Kitty-Hivens Kitty-Hivens changed the title Fixed malformed numbers leaking a NumberFormatException from the JSON parser (#31) Fixed malformed-number parsing (#31) and added java.time mapper support (#23) Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant