How to serialize Map<String, List<Object>> with FlexJSON

不问归期 提交于 2019-12-04 12:18:28
chubbsondubs

Quoi is correct, and most likely the answer you want to use. However, just so you can learn more about how it works you could do this:

new JSONSerializer().include("values.values").serialize( myMap );

Maps and Lists are containers and have special expressions for the elements contained within them. When you want to talk about the path of the values of a container you use "values" expression in the path. Map's two special expressions "keys" and "values". Other Collections have "values".

Another option is to use wildcards like so:

   new JSONSerializer().include("values.*").serialize( myMap );

You can see wildcards used in Quoi's answer as well to exclude the class property.

Try

String jsonString = new JSONSerializer().exclude("*.class").deepSerialize(map);

deepSerialize method performs a deep serialization of the target instance. It will include all collections, maps, and arrays by default so includes are ignored except if you want to include something being excluded by an annotation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!