fix: serialize GetRecords ApproximateArrivalTimestamp as a plain decimal (#2359)

* fix: serialize GetRecords ApproximateArrivalTimestamp as a plain decimal

GetRecords (and SubscribeToShard's event payload) convert ApproximateArrivalTimestamp
from epoch milliseconds by dividing through a double, so Jackson may serialize the
resulting JSON number in scientific notation. AWS SDK for Java v2 then fails to
unmarshal values such as 1.786959659083E9, despite the response returning HTTP 200 -
the same defect as #2099, against a different field/endpoint.

A real, practical consequence: any client that creates a fresh AT_TIMESTAMP shard
iterator for a record that already exists (rather than waiting for a new one to
arrive after polling starts) never finds it - GetRecords's own AT_TIMESTAMP
resolution correctly locates the record server-side, but the client can't parse
the corrupted timestamp on what comes back.

Fix mirrors #2173's approach: a private epochSeconds(Instant) helper returning an
exact BigDecimal (millisecond precision, no exponent notation) instead of a double,
applied at both call sites. Adds focused handler coverage (KinesisJsonHandlerTest)
and an integration test (KinesisIntegrationTest) asserting the raw response body's
timestamp lexeme contains no exponent notation.

Closes #2358

* fix: don't NPE serializing GetRecords when ApproximateArrivalTimestamp is null

KinesisRecord is @RegisterForReflection with a no-arg constructor, so it round-trips
through hybrid/persistent JSON-backed storage - a record persisted by an older Floci
version (or otherwise missing the field) deserializes with a null
approximateArrivalTimestamp. epochSeconds(null) would NPE and fail the whole
GetRecords/SubscribeToShard response over one record. Omit the field instead when
the timestamp is missing, matching how AWS SDKs treat an absent optional field.
This commit is contained in:
sheldon-nadarajah-sft authored and GitHub committed 2026-09-14 15:51:18 -04:00
1 parent 9da589568d
commit 5b4d1aff60
3 files changed
+157 -5

No files matched your search

@@ -365,12 +365,13 @@ public class KinesisJsonHandler {
ObjectNode eventPayload = objectMapper.createObjectNode();
ArrayNode recordsNode = eventPayload.putArray("Records");
for (KinesisRecord rec : records) {
recordsNode.addObject()
ObjectNode recordNode = recordsNode.addObject()
.put("Data", Base64.getEncoder().encodeToString(rec.getData()))
.put("PartitionKey", rec.getPartitionKey())
.put("SequenceNumber", rec.getSequenceNumber())
.put("ApproximateArrivalTimestamp",
rec.getApproximateArrivalTimestamp().toEpochMilli() / 1000.0);
.put("SequenceNumber", rec.getSequenceNumber());
if (rec.getApproximateArrivalTimestamp() != null) {
recordNode.put("ApproximateArrivalTimestamp", epochSeconds(rec.getApproximateArrivalTimestamp()));
}
}
if (continuationSeqNo != null) {
eventPayload.put("ContinuationSequenceNumber", continuationSeqNo);
@@ -671,7 +672,9 @@ public class KinesisJsonHandler {
rNode.put("Data", Base64.getEncoder().encodeToString(rec.getData()));
rNode.put("PartitionKey", rec.getPartitionKey());
rNode.put("SequenceNumber", rec.getSequenceNumber());
rNode.put("ApproximateArrivalTimestamp", rec.getApproximateArrivalTimestamp().toEpochMilli() / 1000.0);
if (rec.getApproximateArrivalTimestamp() != null) {
rNode.put("ApproximateArrivalTimestamp", epochSeconds(rec.getApproximateArrivalTimestamp()));
}
}
response.put("NextShardIterator", (String) result.get("NextShardIterator"));
response.put("MillisBehindLatest", ((Number) result.get("MillisBehindLatest")).longValue());