You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Riaan Annandale <ri...@mundane.co.za> on 2018/07/09 11:11:27 UTC

JSON Arrays

Hi guys

I have a few routes where I convert XML [or maybe SQL so 
java.util.ArrayList] to JSON objects. Depending on the original payload, 
I sometimes get:
{
    "someName":[
       {
          "key1":"value1"
       },
       {
          "key2":"value2"
       }
    ]
}

or if there's only one "key" it might be:
{
    "someName":{
       "key1":"value1"
    }
}

Consumers of these services have serialization issues when it comes to 
the fact that the keys aren't always arrays.

So my question has two parts:
a) Can I tell my data format to have some sort of "always make this an 
array" flag
and/ or
b) do you guy solve this by putting the first result into a POJO first?

or I guess:
c) am I missing the bulls-eye dramatically with my thinking, in which 
case suggestions are very welcome

Thanks
Riaan