From 92ec873ab7113dbde2eed8dbb89f7973b1e38f45 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Tue, 17 Nov 2026 20:24:12 +0000 Subject: [PATCH 1/2] Send second-level UTC offsets as whole minutes Jackson wrote a ZonedDateTime offset with seconds as +HH:MM:SS, for example 1971-06-01T10:00:00-00:44:30 for Africa/Monrovia. RFC 3339 has no seconds in the offset, so the web service ignored the value and returned a warning. Mapper now truncates such an offset to whole minutes and keeps the same instant. The offset stays, because the server uses it for the local time of day. All other values serialize as before. This applies to Event.time, phoneVerificationTime on Billing and Shipping, and Email.verificationTime. Fixes STF-2206. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 ++ .../java/com/maxmind/minfraud/Mapper.java | 34 ++++++++++++ .../java/com/maxmind/minfraud/MapperTest.java | 53 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/test/java/com/maxmind/minfraud/MapperTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 554b2196..c6ee5144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,11 @@ CHANGELOG response values, for example `business` and `live`, deserialized as `null`. The library now uses `Locale.ROOT` for these case conversions. * Added `RYFT` to the `Payment.Processor` enum. +* A `ZonedDateTime` request value whose UTC offset has non-zero seconds is + now sent with the offset truncated to whole minutes. The instant does not + change. Previously, the web service ignored these values and returned a + warning. This affects `Event.time`, `phoneVerificationTime` on `Billing` + and `Shipping`, and `Email.verificationTime`. 4.4.0 (2026-07-21) ------------------ diff --git a/src/main/java/com/maxmind/minfraud/Mapper.java b/src/main/java/com/maxmind/minfraud/Mapper.java index d383e646..441b3d86 100644 --- a/src/main/java/com/maxmind/minfraud/Mapper.java +++ b/src/main/java/com/maxmind/minfraud/Mapper.java @@ -1,17 +1,28 @@ package com.maxmind.minfraud; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.util.StdDateFormat; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.io.IOException; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; class Mapper { private static final ObjectMapper mapper = JsonMapper.builder() .addModule(new JavaTimeModule()) + // Added after JavaTimeModule so that it replaces its ZonedDateTime serializer. + .addModule(new SimpleModule() + .addSerializer(ZonedDateTime.class, new WholeMinuteOffsetSerializer())) .defaultDateFormat(new StdDateFormat().withColonInTimeZone(true)) .enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) .enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING) @@ -26,4 +37,27 @@ class Mapper { public static ObjectMapper get() { return mapper; } + + /** + * Writes a {@code ZonedDateTime} with {@code ISO_OFFSET_DATE_TIME}. RFC 3339 offsets have no + * seconds, so an offset with seconds is truncated to whole minutes. The instant does not + * change. + */ + private static final class WholeMinuteOffsetSerializer + extends StdSerializer { + WholeMinuteOffsetSerializer() { + super(ZonedDateTime.class); + } + + @Override + public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider provider) + throws IOException { + int offsetSeconds = value.getOffset().getTotalSeconds(); + if (offsetSeconds % 60 != 0) { + var offset = ZoneOffset.ofTotalSeconds(offsetSeconds / 60 * 60); + value = value.withZoneSameInstant(offset); + } + gen.writeString(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value)); + } + } } diff --git a/src/test/java/com/maxmind/minfraud/MapperTest.java b/src/test/java/com/maxmind/minfraud/MapperTest.java new file mode 100644 index 00000000..bb5277e1 --- /dev/null +++ b/src/test/java/com/maxmind/minfraud/MapperTest.java @@ -0,0 +1,53 @@ +package com.maxmind.minfraud; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +public class MapperTest { + + static Stream zonedDateTimes() { + return Stream.of( + // Offsets with seconds are truncated to whole minutes. + Arguments.of( + ZonedDateTime.of(1971, 6, 1, 10, 0, 0, 0, ZoneId.of("Africa/Monrovia")), + "1971-06-01T10:00:30-00:44"), + Arguments.of( + ZonedDateTime.of(2026, 10, 1, 10, 0, 0, 0, + ZoneOffset.ofHoursMinutesSeconds(5, 30, 15)), + "2026-10-01T09:59:45+05:30"), + Arguments.of( + ZonedDateTime.of(2026, 10, 1, 10, 0, 0, 0, + ZoneOffset.ofHoursMinutesSeconds(-5, -30, -15)), + "2026-10-01T10:00:15-05:30"), + Arguments.of( + ZonedDateTime.of(2026, 1, 1, 0, 0, 0, 0, ZoneOffset.ofTotalSeconds(-59)), + "2026-01-01T00:00:59Z"), + // Other values are unchanged. + Arguments.of( + ZonedDateTime.of(2026, 10, 1, 10, 30, 0, 0, ZoneId.of("America/New_York")), + "2026-10-01T10:30:00-04:00"), + Arguments.of( + ZonedDateTime.of(2026, 10, 1, 10, 30, 0, 123456789, ZoneId.of("Asia/Kolkata")), + "2026-10-01T10:30:00.123456789+05:30"), + Arguments.of( + ZonedDateTime.parse("2026-10-05T23:20:50.52Z"), + "2026-10-05T23:20:50.52Z") + ); + } + + @ParameterizedTest + @MethodSource("zonedDateTimes") + public void testZonedDateTimeSerialization(ZonedDateTime time, String expected) + throws Exception { + var json = Mapper.get().writeValueAsString(time); + assertEquals("\"" + expected + "\"", json); + assertEquals(time.toInstant(), ZonedDateTime.parse(expected).toInstant()); + } +} From 541e2ab7c8a83988b4339472b118a8a86ec0fa06 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Tue, 17 Nov 2026 22:51:29 +0000 Subject: [PATCH 2/2] Round second-level UTC offsets to the nearest minute The last example in RFC 3339 section 5.8 shows an offset with seconds. It keeps the instant and uses the closest whole-minute offset. Round the offset to match it, not truncate. For example, +05:30:45 becomes +05:31, not +05:30. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- src/main/java/com/maxmind/minfraud/Mapper.java | 7 ++++--- .../java/com/maxmind/minfraud/MapperTest.java | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6ee5144..5c33b64f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ CHANGELOG `null`. The library now uses `Locale.ROOT` for these case conversions. * Added `RYFT` to the `Payment.Processor` enum. * A `ZonedDateTime` request value whose UTC offset has non-zero seconds is - now sent with the offset truncated to whole minutes. The instant does not + now sent with the offset rounded to the nearest minute. The instant does not change. Previously, the web service ignored these values and returned a warning. This affects `Event.time`, `phoneVerificationTime` on `Billing` and `Shipping`, and `Email.verificationTime`. diff --git a/src/main/java/com/maxmind/minfraud/Mapper.java b/src/main/java/com/maxmind/minfraud/Mapper.java index 441b3d86..a4d0157e 100644 --- a/src/main/java/com/maxmind/minfraud/Mapper.java +++ b/src/main/java/com/maxmind/minfraud/Mapper.java @@ -40,8 +40,8 @@ public static ObjectMapper get() { /** * Writes a {@code ZonedDateTime} with {@code ISO_OFFSET_DATE_TIME}. RFC 3339 offsets have no - * seconds, so an offset with seconds is truncated to whole minutes. The instant does not - * change. + * seconds, so an offset with seconds is rounded to the nearest minute, as in the last + * example in RFC 3339 section 5.8. The instant does not change. */ private static final class WholeMinuteOffsetSerializer extends StdSerializer { @@ -54,7 +54,8 @@ public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider throws IOException { int offsetSeconds = value.getOffset().getTotalSeconds(); if (offsetSeconds % 60 != 0) { - var offset = ZoneOffset.ofTotalSeconds(offsetSeconds / 60 * 60); + var minutes = (int) Math.round(offsetSeconds / 60.0); + var offset = ZoneOffset.ofTotalSeconds(minutes * 60); value = value.withZoneSameInstant(offset); } gen.writeString(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value)); diff --git a/src/test/java/com/maxmind/minfraud/MapperTest.java b/src/test/java/com/maxmind/minfraud/MapperTest.java index bb5277e1..28dca0c1 100644 --- a/src/test/java/com/maxmind/minfraud/MapperTest.java +++ b/src/test/java/com/maxmind/minfraud/MapperTest.java @@ -14,7 +14,8 @@ public class MapperTest { static Stream zonedDateTimes() { return Stream.of( - // Offsets with seconds are truncated to whole minutes. + // Offsets with seconds are rounded to the nearest minute. Math.round rounds + // -44.5 minutes to -44. Arguments.of( ZonedDateTime.of(1971, 6, 1, 10, 0, 0, 0, ZoneId.of("Africa/Monrovia")), "1971-06-01T10:00:30-00:44"), @@ -27,8 +28,16 @@ static Stream zonedDateTimes() { ZoneOffset.ofHoursMinutesSeconds(-5, -30, -15)), "2026-10-01T10:00:15-05:30"), Arguments.of( - ZonedDateTime.of(2026, 1, 1, 0, 0, 0, 0, ZoneOffset.ofTotalSeconds(-59)), - "2026-01-01T00:00:59Z"), + ZonedDateTime.of(2026, 10, 1, 10, 0, 0, 0, + ZoneOffset.ofHoursMinutesSeconds(5, 30, 45)), + "2026-10-01T10:00:15+05:31"), + Arguments.of( + ZonedDateTime.of(2026, 10, 1, 10, 0, 0, 0, + ZoneOffset.ofHoursMinutesSeconds(-5, -30, -45)), + "2026-10-01T09:59:45-05:31"), + Arguments.of( + ZonedDateTime.of(2026, 1, 1, 0, 0, 0, 0, ZoneOffset.ofTotalSeconds(-29)), + "2026-01-01T00:00:29Z"), // Other values are unchanged. Arguments.of( ZonedDateTime.of(2026, 10, 1, 10, 30, 0, 0, ZoneId.of("America/New_York")),