将JSON解组到映射/字符串列表 [英] Unmarshal JSON to Map/List of Strings
问题描述
我想将Json解组到字符串的映射/列表(例如Map> ...)
I would like to unmarshal a Json to a Map/List of Strings (eg 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"}]}
}}
在整理后,我希望能够做这样的事情":
I would like to be able to do "something" like this after unmarshaling:
myJsonMapped.get("pointsOfSale").get("pointOfSale").get(0).get("source").get("href").equals("\/sources\/TEST") == true
例如,使用Gson,我们可以执行这种解码:
For instance, with Gson we can do this kind of decoding:
new Gson().fromJson(json, Map.class);
我知道我可以使用简单的bean或处理器等来完成此操作...
I know I can do this with a simple bean or processor etc...
我只想知道我可以使用本机JSON骆驼组件配置
I just want to know of I can do this more efficiently with a native JSON camel component config
我已经尝试了类似的其他操作: unmarshal().json()... 或者 unmarshal().json(JsonLibrary.Gson,Map.class).. 等等... 没有成功:'(
I tried different thing already like : unmarshal().json()... or unmarshal().json(JsonLibrary.Gson, Map.class).. etc... without succes :'(
推荐答案
您可以使用杰克逊做类似的事情.
You could do something like this with jackson.
<dataFormats>
<json id="jack" library="Jackson"/>
</dataFormats>
...
<route>
<from uri="direct:test"/>
<unmarshal ref="jack"/>
<process ref="something"/>
</route>
或在带有gson的Java中:
Or in java with gson:
from("foo:bar")
.unmarshal().json(JsonLibrary.Gson,Map.class)
.to("foo:baz");
如果您无法使它正常工作,请指出错误,并排在第四位.
If you're not getting it to work, please state error and so fourth.
这篇关于将JSON解组到映射/字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!