解组 JSON 以映射/字符串列表

cyr*_*ech 5 json apache-camel

我想将 Json 解组为 Map/List of Strings(例如 Map>...)

这是我的输入:

{"pointsOfSale": 
{"pointOfSale":[ 
{"href":"\/pointsOfSale\/UUID.0abc2aca-7930-4c9e-9f38-8af3d0692e04", 
"model":{"href":"\/models\/modelePointOfSale", 
"modelType":{"href":"\/modelTypes\/pointOfSale"}}, 
"source":{"href":"\/sources\/TEST"}, 
"attribute":[ 
{"code":"pointOfSalePhysical","value":true}, 
{"code":"mail","value":"Mail1"}, 
{"code":"adresse","value":"address1"}]}, 
{"href":"\/pointsOfSale\/UUID.a12e7adf-652a-4197-91bf-d4785e43f09f", 
"model":{"href":"\/models\/modelePointOfSale", 
"modelType":{"href":"\/modelTypes\/pointOfSale"}}, 
"source":{"href":"\/sources\/Wikeo"}, 
"attribute":[ 
{"code":"pointOfSalePhysical","value":false}, 
{"code":"mail","value":"Mail1"}, 
{"code":"adresseMateriau","value":"Material address1"}]} 
}}
Run Code Online (Sandbox Code Playgroud)

我希望能够在解组后做这样的“事情”:

myJsonMapped.get("pointsOfSale").get("pointOfSale").get(0).get("source").get("href").equals("\/sources\/TEST") == true 
Run Code Online (Sandbox Code Playgroud)

例如,我们可以使用 Gson 进行这种解码:

new Gson().fromJson(json, Map.class); 
Run Code Online (Sandbox Code Playgroud)

我知道我可以用一个简单的 bean 或处理器等来做到这一点......

我只是想知道我可以使用本机 JSON 骆驼组件配置更有效地做到这一点

编辑:我已经尝试了不同的东西,比如: unmarshal().json()... 或 unmarshal().json(JsonLibrary.Gson, Map.class).. 等等...没有成功:'(

Pet*_*der 3

你可以和杰克逊一起做类似的事情。

<dataFormats>
  <json id="jack" library="Jackson"/>
</dataFormats>

...

<route>
  <from uri="direct:test"/>
  <unmarshal ref="jack"/>
  <process ref="something"/>
</route>
Run Code Online (Sandbox Code Playgroud)

或者在java中使用gson:

 from("foo:bar")
    .unmarshal().json(JsonLibrary.Gson,Map.class)
    .to("foo:baz");
Run Code Online (Sandbox Code Playgroud)

如果您无法使其正常工作,请说明错误等等。