Hi,
I'm trying to send a JSON to a MQTT which contains hierarchy:
{
"reference": "1",
"confirmed": true,
"fPort": 1,
"object": {
"data": 50
}
}
I created the following GeoeventDefintion:
Because the incoming GeoEventDefintion looks different (plain JSON-Structure without hierarchy), I try to use the FieldMapper:
Unfortunately this does not work 😞
Looks like FieldMapper cannot handle hierarchy !?
Is this the wrong approach?
Any help is appreciated ...
Hi,
flatten an incoming json with hierachy works fine, so the fieldmapper can handle hierachy. This is a standard workflow where I use FieldMapper.
I've just tested the other way around and get the same error message you got.
-1 java.lang.ArrayIndexOutOfBoundsException
This looks like the FieldMapper is not initializing the Group before trying to set the value.
I've also tried to create a GeoEvent Definition that contains all source and target fields. In this case i expected that the initialization error does not occur any more. And the error is gone, but the JSON output only contains the top element of the hierachy and not the expected values I set in the FieldMapper.
So i did not find any quick solution.
Edit: You could create a GeoEvent Definition with all fields and use the FieldCalculator to set the value for the fields in hierachy. Not the best solution, cause you Need a FieldCalculator per field, but maybe a Workaround. At the End a FieldReducer to get rid of the flat fields.
Best,
Stefan
Thanks Stefan for your advice,
meanwhile we took another approach and created a custom processor "ComplexJSONSetter".
I took a little while to get started but in the end we managed setting the needed hierarchy structure.
As you mentioned, FieldMapper can handle incoming hierarchy. This is our experience as well.
What's your opinion: Shouldn't FieldMapper support setting hierarchy too?
Ist that a change request?
From our point of view it is at least an unwanted behaviour.
Thanks for your comment.