How to specify map properties in Struts 2 JSON Plugin
I'm using Struts 2 along with the json plugin, the properties mappings in the struts.xml file are typically frustrating but I am able to figure them out.
I have come across a case where I cannot set the includeProperties to give me the result I expect.
Frequently I use a configuration expression
^itemList\[\d+\]\.id,
^itemList\[\d+\]\.name
....
This works well.
In this case I would like to return data from a Map not a list (or a map that's a child of a 开发者_JAVA百科list member)
If a * is used the whole map is printed out correctly, but I do not want all the data from the map elements.
^itemList\[\d+\]\map\.*
The whole map is returnd
I have tried several different formats and none of them have produced results.
^itemList\[\d+\]\map\[\d+\]\.id
^itemList\[\d+\]\map\[\d+\]\.name
Nothing is returned in the map property
Anyone had any luck with a syntax to restrict the contents of a map?
Thanks -Scott
You cannot use 'd' it map as integer.
Try this ^itemList\..*$
1) Your regular expression is suspicious. Note that in the expression "^itemList[\d+]\map[\d+].id", +d refers to one more more digits, so the map would have to have digit(s) as it's key. If this is not what you want, then '.+' is probably more appropriate (one or more of any character).
2) Convert the Map to a LinkedHashMap and then treat it as a list. (Have not tested this, it might not work)
精彩评论