File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
src/main/java/de/rwth/idsg/steve/ocpp/ws Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 99import de .rwth .idsg .steve .ocpp .ws .ocpp15 .Ocpp15JacksonModule ;
1010import de .rwth .idsg .steve .ocpp .ws .ocpp16 .Ocpp16JacksonModule ;
1111
12+ import static com .fasterxml .jackson .databind .DeserializationFeature .FAIL_ON_NULL_FOR_PRIMITIVES ;
13+
1214/**
1315 * Because ObjectMapper can and should be reused, if config does not change after init.
1416 *
@@ -24,6 +26,15 @@ public enum JsonObjectMapper {
2426 mapper = new ObjectMapper ();
2527 mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
2628
29+ // OCPP messages contain some mandatory primitive fields (like transactionId), that are not allowed
30+ // to be null. any misinterpretation/mapping of these fields like "null -> 0" is a mistake.
31+ //
32+ // true story: while testing with abusive-charge-point, it sends stopTransactions where transactionId=null
33+ // in communication flows, where a startTransaction before causes an Exception and we cannot send a regular
34+ // response with a transactionId, but an error message. if we do not fail early, it will fail at the database
35+ // level which we want to prevent.
36+ mapper .configure (FAIL_ON_NULL_FOR_PRIMITIVES , true );
37+
2738 mapper .registerModule (new Ocpp12JacksonModule ());
2839 mapper .registerModule (new Ocpp15JacksonModule ());
2940 mapper .registerModule (new Ocpp16JacksonModule ());
You can’t perform that action at this time.
0 commit comments