struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Micael Carreira <mcarre...@itclinical.com>
Subject Re: JSON plugin: filter fields in a Map with Lists
Date Fri, 27 Sep 2019 11:59:23 GMT
Thanks, that indeed works Yasser.

However, with that configuration I won't have access to the map keys, 
which I also need. For now, I created a new getter that retrieves only 
the keys, but this is a workaround.

However from what you said, I guess it is not possible to have both the 
keys and values filtered in a map structure as I originally wanted, right?

Thanks again for your help,
Email Signature
Micael Carreira
Software Developer 	Logo 
<https://www.itclinical.com&utm_source=mail&utm_medium=banner&utm_campaign=signature>


Rua Augusto Macedo, 12-B
1600-794 Lisbon - Portugal
t: +351 21 714 4500
www.itclinical.com 
<http://www.itclinical.com&utm_source=mail&utm_medium=banner&utm_campaign=signature>

	Facebook icon <https://www.facebook.com/ITClinical> LinkedIn icon 
<https://www.linkedin.com/company/itclinical>
The content of this email is confidential and intended for the recipient 
specified in message only. It is strictly forbidden to share any part of 
this message with any third party, without a written consent of the 
sender. If you received this message by mistake, please reply to this 
message and follow with its deletion, so that we can ensure such a 
mistake does not occur in the future.

On 26/09/19 22:25, Yasser Zamani-2 [via Struts] wrote:
> Hi Micael, thanks for your report!
>
> You're right! I debugged Struts with your model, Map<String,
> List<MyObject>>. I realized with following sample initialization:
>
>          MyObject mo = new MyObject();
>          mo.setInterestingProperty("IP");
>          mo.setNotInterestingProperty("NIP");
>          ArrayList<MyObject> mol = new ArrayList<MyObject>();
>          mol.add(mo);
>          result = new HashMap<>();
>          result.put("first", mol);
>
> Struts checks result.first[0].interestingProperty if it has any
> includeProperties matches.
>
> The map key can be any string i.e. .* Consequently you have to have
> result\..*\[\d+\]\.interestingProperty but .* causes including all of
> the model -- because Struts splits above into multiple regex: result,
> result\..*, result\..*\[\d+\] and result\..*\[\d+\]\.interestingProperty
> and checks input with them respectively. The second one passes all!
>
> I just could find following workaround which you might like:
>
>      private Map<String, List<MyObject>> result;
>      public Collection<List<MyObject>> getResult() {
>          return result.values();
>      }
> 	<param name="includeProperties">
> 		^result$,^result\[\d+\]\[\d+\]\.interestingProperty$
> 	</param>
>
> Hope this helps!
>
> Best.
>
> On 9/25/2019 8:57 PM, Micael Carreira wrote:
>> Hello Yasser, thanks for your reply.
>>
>> It did not work. The configuration you suggested, sends nothing in JSON
>> object.
>>
>> I also tried this configuration:
>>
>> <param name="includeProperties">
>>      result\..+,
>>      result,interestingProperty
>> </param>
>>
>> But it sends all properties, including notInterestingProperty.
>>
>> Best regards,
>>
>> Email Signature
>> Micael Carreira
>> Software Developer     Logo
>> <https://www.itclinical.com&utm_source=mail&utm_medium=banner&utm_campaign=signature>
>>
>> Rua Augusto Macedo, 12-B
>> 1600-794 Lisbon - Portugal
>> t: +351 21 714 4500
>> www.itclinical.com
>> <http://www.itclinical.com&utm_source=mail&utm_medium=banner&utm_campaign=signature>
>>      Facebook icon <https://www.facebook.com/ITClinical> LinkedIn icon
>> <https://www.linkedin.com/company/itclinical>
>> The content of this email is confidential and intended for the recipient
>> specified in message only. It is strictly forbidden to share any part of
>> this message with any third party, without a written consent of the
>> sender. If you received this message by mistake, please reply to this
>> message and follow with its deletion, so that we can ensure such a
>> mistake does not occur in the future.
>>
>> On 25/09/19 09:18, Yasser Zamani-2 [via Struts] wrote:
>>>> -----Original Message-----
>>>> From: Micael Carreira <mcarreira@itclinical.com>
>>>> Sent: Tuesday, September 24, 2019 1:30 PM
>>>> To: user@struts.apache.org
>>>> Subject: JSON plugin: filter fields in a Map with Lists
>>>>
>>>> Hello,
>>>>
>>>> In MyAction, I have the following instance variable:
>>>>
>>>>       Map<String, List<MyObject>> result;
>>>>
>>>> And MyObject has the following properties:
>>>>
>>>>       MyObject
>>>>       |- interestingProperty
>>>>       |- notInterestingProperty
>>>>
>>>> I want to return the action result as a JSON. So, in my struts
>>>> configuration I have:
>>>>
>>>>       <action name="MyAction" method="execute" class="myAction">
>>>>           <result name="success" type="json">
>>>>               <param name="includeProperties">
>>>>                   result\..+$
>>>>               </param>
>>>>           </result>
>>>>       </action>
>>>>
>>>> This returns all keys/values in result map. But I want to write a
>>>> JSON with only
>>>> interestingProperty of each MyObject (which are in a list).
>>> Hi,
>>>
>>> Doesn't below work for you (to write only interestingProperty)?
>>>
>>> <param name="includeProperties">
>>> result,interestingProperty
>>> </param>
>>>
>>> Regards.
>>>
>>>> I've fiddled with the regular expression for a while, but could not
>>>> find a way to do
>>>> it.
>>>>
>>>> Is it possible to achieve what I need?
>>>>
>>>> Thanks,
>>>>
>>>> -- 
>>>> Email Signature
>>>> Micael Carreira
>>>> Software Developer     Logo
>>>> <https://www.itclinical.com&utm_source=mail&utm_medium=banner&utm_cam
>>>> paign=signature>
>>>>
>>>> Rua Augusto Macedo, 12-B
>>>> 1600-794 Lisbon - Portugal
>>>> t: +351 21 714 4500
>>>> www.itclinical.com
>>>> <http://www.itclinical.com&utm_source=mail&utm_medium=banner&utm_cam
>>>> paign=signature>
>>>>      Facebook icon <https://www.facebook.com/ITClinical> LinkedIn
icon
>>>> <https://www.linkedin.com/company/itclinical>
>>>> The content of this email is confidential and intended for the
>>>> recipient specified in
>>>> message only. It is strictly forbidden to share any part of this
>>>> message with any
>>>> third party, without a written consent of the sender. If you received
>>>> this message
>>>> by mistake, please reply to this message and follow with its
>>>> deletion, so that we
>>>> can ensure such a mistake does not occur in the future.
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message