SoftwareAG / cumulocity-dynamic-mapper

The ultimate Mapper for building the bridge between any Message Broker and Cumulocity IoT in a zero-code approach!
Apache License 2.0
9 stars 9 forks source link

Parsing failure of JSON with reserved keywords #230

Open karchevskii opened 2 weeks ago

karchevskii commented 2 weeks ago

Initial situation

There is a people counter sensor, that sends data via MQTT on C8Y. The MQTT looks like:

{
    "device_info": {
        "device_mac": "24:E1:24:F9:28:00",
        "device_name": "People Counter",
        "device_sn": "6757D50072250018",
        "firmware_version": "V_[133.1.0.7](https://133.1.0.7/)",
        "hardware_version": "V1.3",
        "ip_address": "[192.168.1.101](https://192.168.1.101/)",
        "running_time": 169576
    },
    "line_periodic_data": [
        {
            "children_in": 0,
            "children_out": 0,
            "empty_cart_in": 0,
            "empty_cart_out": 0,
            "full_cart_in": 0,
            "full_cart_out": 0,
            "group_in": 0,
            "group_out": 0,
            "in": 122,
            "line": 1,
            "line_name": "Line1",
            "line_uuid": "fd077b55-8717-449d-85b2-986d2e9deba1",
            "no_full_cart_in": 0,
            "no_full_cart_out": 0,
            "out": 0,
            "staff_in": 0,
            "staff_out": 0
        }
    ],
    "line_total_data": [
        {
            "capacity_counted": -163,
            "children_in_counted": 0,
            "children_out_counted": 29,
            "empty_cart_in_counted": 0,
            "empty_cart_out_counted": 0,
            "full_cart_in_counted": 1,
            "full_cart_out_counted": 2,
            "group_in_counted": 10,
            "group_out_counted": 173,
            "in_counted": 10,
            "line": 1,
            "line_name": "Line1",
            "line_uuid": "fd077b55-8717-449d-85b2-986d2e9deba1",
            "no_full_cart_in_counted": 0,
            "no_full_cart_out_counted": 0,
            "out_counted": 173,
            "staff_in_counted": 0,
            "staff_out_counted": 0
        }
    ],
    "time_info": {
        "dst_status": true,
        "enable_dst": true,
        "end_time": "2024-08-22T14:56:00+02:00",
        "start_time": "2024-08-22T14:55:00+02:00",
        "time_zone": "UTC+1:00 Central European Time (CET)"
    }
}

pay attention to the field with the nameìn.

The dynamic-mapper version is 4.4.0 (latest)

Error

While mapping of the JSON, the error occurs if we try to map the fild ìn`:

at com.api.jsonata4java.expressions.Expressions.parse(expressions.java:113)
 at dynamic.mapping.processor.inbound.JSONProcessorInbound.extractFromSource(jsonprocessorinbound.java:108)
 at dynamic.mapping.processor.inbound.AsynchronousDispatcherInbound$MappingInboundTask.lambda$call$1(asynchronousdispatcherinbound.java:203)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
 at dynamic.mapping.processor.inbound.AsynchronousDispatcherInbound$[MappingInboundTask.call](https://mappinginboundtask.call/)(asynchronousdispatcherinbound.java:137)
 at dynamic.mapping.processor.inbound.AsynchronousDispatcherInbound$[MappingInboundTask.call](https://mappinginboundtask.call/)(asynchronousdispatcherinbound.java:100)
 at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
 at java.base/java.lang.Thread.run(Thread.java:829)

2024-08-22 13:14:04.173  WARN 12 --- [ol-1-thread-202] d.m.p.inbound.JSONProcessorInbound       : Tenant <tenant> - Substitution line_periodic_data[0].in not in message payload. Check your mapping counter/+
2024-08-22 13:14:04.197  INFO 12 --- [ol-1-thread-202] dynamic.mapping.core.C8YAgent            : Tenant <tenant> - New measurement posted: {"self":"<url>","time":"2024-08-22T13:14:04.173Z","source":{"self":"<url>","id":"<id>"},"id":"<id>","type":"c8y_PeopleCounter","c8y_PeopleCounter":{"children_in":{"unit":"","value":0},"children_out":{"unit":"","value":0},"adults_out":{"unit":"","value":0},"group_in":{"unit":"","value":0},"group_out":{"unit":"","value":0}}}

Fix

On the MQTT Broker (EMQX) we fixed it renaming of the field from ìntopeople_in`. The rule engine of EMQX was utilized:

FOREACH 
    jq('.line_periodic_data[] |= (.people_in = .in | del(.in))', payload) as modified_payload
DO 
    modified_payload.device_info,
    modified_payload.line_periodic_data,
    modified_payload.line_total_data,
    modified_payload.time_info
sagIoTPower commented 2 weeks ago

This looks like an issue with the JSONata4Java library. I will open a ticket in this project.

sagIoTPower commented 2 weeks ago

Raised issue in the JSONata4Java project.

sagIoTPower commented 1 week ago

We documented this limitation. There seems to. be no other word around than renaming or removing the keys.