feat(websocket): let the CSMS choose how a timestamp without timezone is read, per charging station
Problem
Since 3.0.0, an inbound timestamp with no timezone is accepted and read as UTC, with a warning (InstantDeserializer.parseInstantWithoutTimezone). The release notes describe this as a deliberate interoperability choice. It is a good default, but a CSMS cannot change it.
A charging station that sends its local time without an offset therefore gets silently shifted timestamps. For a station in Europe/Paris, 2024-03-15T12:00:00 is stored as 12:00 UTC instead of 11:00 UTC. In 2.0.4 the same frame was refused with a CallError, so the problem was visible; in 3.0.0 nothing fails, and transaction start and stop times and meter values are simply wrong.
Only the operator knows what such a station means: it depends on the station's configuration and location, so no single global value can be right.
The CSMS cannot fix this on its side:
- The zone is hardcoded:
.atZone(ZoneOffset.UTC). - The deserializer has no access to the charging station:
Ocpp16JsonObjectMapperis shared, andgetJsonMapperinocpp-transport-websocketisinternal. - After parsing, the application receives an
Instant, so it can no longer tell a timestamp that had no timezone from one that saidZ. Correcting it afterwards would also shift the correct values.
The warning does not help find the stations either: Timestamp without timezone received: {}. Interpreting it as UTC. logs the value but not the charging station id.
Proposal
Add a per-station setting to the WebSocket server transport, keeping today's behaviour as the default. Sketch only, not compiled:
class WebsocketServer(
ocppVersions: Set<OcppVersion>,
path: String,
val newMessageId: () -> String = { UUID.randomUUID().toString() },
settings: OcppWampServerSettings = OcppWampServerSettings(),
listeners: EventsListeners = EventsListeners(),
// Zone used to read a timestamp that has none. Default: UTC, as today.
timestampZoneFallback: (CSOcppId) -> ZoneId = { ZoneOffset.UTC },
)
parsePayloadFromJson could carry the zone per call through a Jackson attribute (ObjectReader.withAttribute), which InstantDeserializer reads from its DeserializationContext. The mapper stays shared, and calls without the attribute keep reading UTC.
A dedicated resolver seems better than a new ChargingStationConfig field: that config answers a connection-time question, and implementations may hit a database to build it, whereas this lookup runs per message. It also needs to cover both directions of WebsocketServer: receiveMessageClass for inbound calls, and sendMessageClass for the results of calls the CSMS sent.
Acceptance criteria
- With no setting, behaviour is unchanged: UTC and a warning.
- With a resolver returning
Europe/Paris,2024-03-15T12:00:00reads as2024-03-15T11:00:00Z. - Timestamps with
Z,+02:00or+02are never affected by the resolver. - A value that is no timestamp still produces a CallError.
- A daylight saving overlap or gap follows
LocalDateTime.atZone, and a test documents it. - The warning includes the charging station id and the zone used.
- It works on results of CSMS-initiated calls as well as on inbound calls, covered by a test for each direction.
Open questions
- Should a CSMS also be able to refuse these timestamps? Making the resolver return
ZoneId?, withnullmeaning "refuse with a CallError" as in 2.0.4, would cover operators who prefer a visible failure. It costs little and avoids a second setting later. - Where should the setting be exposed?
ServerSettingwould need it too for users of the high-level API, the same waywampSettingsis threaded down. - What about
parseAnyFromString? It runs JSON schema validation, whereparsePayloadFromJsondoes not, so the two paths may disagree on these values. Should they be aligned? - Is SOAP in scope? This proposal only covers OCPP-J.
Compatibility
The new parameter has a default and goes last, so source compatibility holds for existing callers, which matters here because 3.0.0 already had to move listeners. JVM binary compatibility of the constructor needs checking.
The per-call reader attribute approach seems a good boundary for keeping station policy out of the shared mapper. I'd add an isolation regression alongside the proposed date cases: reuse one mapper/deserializer, interleave reads for two station zones, then read a third message with no attribute. That last read must return to the UTC default, not inherit whichever station ran previously. ObjectReader configuration is immutable, so the zone/id should be read from each call's DeserializationContext, not stored in an InstantDeserializer field.
For the specified LocalDateTime.atZone policy, two explicit Paris fixtures would make the DST contract reviewable:
2026-03-29T02:30:00(gap) resolves to2026-03-29T01:30:00Z, after moving forward through the gap.2026-10-25T02:30:00(overlap) resolves to2026-10-25T00:30:00Z, choosing the earlier offset.
A refusal mode should only apply after determining that the input has no offset: an explicitly offset timestamp should continue to work even for a station configured to refuse offset-free values. That gives an extra cross-product test for the nullable-resolver option, beyond testing each input form independently.