Sending JSON with hierarchy

599
2
01-30-2019 08:48 AM
MartinThoma
New Contributor

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:

GeoeventDef to send

Because the incoming GeoEventDefintion looks different (plain JSON-Structure without hierarchy), I try to use the FieldMapper:

FieldMapper

Unfortunately this does not work 😞

ErrorLog

Looks like FieldMapper cannot handle hierarchy !?

Is this the wrong approach?

Any help is appreciated ...

Tags (2)
2 Replies
Stefan_Jung
Esri Contributor

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

MartinThoma
New Contributor

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.

0 Kudos