Since no one seems to have posted an answer anywhere (and this exact same
problem stumped me for a while), I thought I'd share what worked for me.

I loaded the jsonplugin code and figured out what I needed to do to use the
"includeProperties" param to only serialize a certain property of my list. 
It seems that you also need to include the parent objects in your
includeProperties parameters.

Using your Map below, if you only wanted to serialize "myProperty" member of
your map, your includeProperties would look something like:


  productCategoriesMap,
  productCategoriesMap\[\d+\],       <--- in this case, the index is an
integer, but yours might be a string
  productCategoriesMap\[\d+\].myProperty


While stepping through the code, I found that as the jsonplugin is walking
the object hierarchy, it starts at the parent, which is
"productCategoriesMap."  It will then look to see if it should include this
property -- unless you have a rule in there to allow this, it won't continue
walking productCategoriesMap to get to "myProperty," which is why when you
only specify a rule for productCategoriesMap\[\d+\].myProperty, it
serializes nothing.  

Hope this helps!


Gadbury wrote:
> 
> The first regex returns nothing and the second everything (as before).  My
> regex is pretty poor but if I ignore regex, what would the syntax be for
> accessing the property of a bean is a list in the map.  i.e. given the
> map:
> 
> private Map<String, List<Category>> productCategoriesMap
> 
> Would it be:
> 
> myMap['myKey'].beanProperty    
> myMap.myKey.beanProperty      
> 
> or both, I seem to recall?
> 
> Is it definitely possible to filter out properties of beans within a map
> using 0.33 / 0.34 (I've tried both) of the json plugin?
> 
> Sorry to go on aout this - it's been driving me crazy all day :)
> 
> 
> Musachy Barroso wrote:
>> 
>> Java regexes are greedy by default if I dont remember wrong, so you
>> should try something like:
>> 
>> productCategoriesMap[.*?]\.name
>> 
>> or
>> 
>> productCategoriesMap\..*?\.name
>> 
>> musachy
>> 
>> On Tue, Sep 1, 2009 at 6:15 AM, Gadbury<gadb...@googlemail.com> wrote:
>>>
>>> Hi,
>>>
>>> Sorry to jump a (dead?) thread but it's relevant to what I am trying to
>>> do
>>> and it made sense to put it in the same thread.
>>>
>>> I have the following HashMap:
>>>
>>> private Map<String, List<Category>> productCategoriesMap;
>>>
>>> in my includeProperties, productCategoriesMap.* populates the json with
>>> every property of the Category bean.  For example:
>>>
>>>        {
>>>        "productCategoriesMap":{"ac80e9b6-29e6-4f00-9410-1a18a9dfd317":[{
>>>                "UUID":"4bd497a1-bd1b-417b-8d62-e1273fa5e648",
>>>                "name":"Test Sub-Category EDIT",
>>>              
>>>  "parentCategoryUUID":"65750a38-d596-48d7-a215-56bcb21d8067",
>>>              
>>>  "providerRepositoryUUID":"69011624-112a-457b-a222-edd3b543e585"
>>>                },{
>>>                "UUID":"65750a38-d596-48d7-a215-56bcb21d8067",
>>>                "name":"Category 4",
>>>              
>>>  "parentCategoryUUID":"98e4b067-5b6b-4777-a28a-443a77209948",
>>>              
>>>  "providerRepositoryUUID":"69011624-112a-457b-a222-edd3b543e585"
>>>                }]
>>>        }
>>>
>>> However, I would like to only include UUID and name, as an example.  I
>>> have
>>> tried:
>>>
>>> productCategoriesMap.*.name
>>> productCategoriesMap.*.*
>>> productCategoriesMap[*].name
>>> productCategoriesMap.*\.name
>>> productCategoriesMap\.*\.name
>>>
>>> How do I use includeProperties to filter properties of beans within a
>>> map?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/JSON-plugin-ignoring-includeProperties-parameter-tp23660860p25240134.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>
>>>
>> 
>> 
>> 
>> -- 
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/JSON-plugin-ignoring-includeProperties-parameter-tp23660860p27471936.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to