Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return json data selectively in a struts2 action class

Tags:

java

json

struts2

I have several properties with getter and setter method in one action class.

Those properties do not perform the same task. Actually, they respond to different business-service requests, or they are related to different actions.

And my problem is like this:

I need to filter out the data and return only part of the properties within the property set because not all properties are necessary in a single request(action).

PS:Actually, I might have separated those actions or business logic into several classes instead of putting them into one action class. However, I think they all share the similar DAOs and services so I put them together in order to prevent redundant IOCs.

like image 836
xiaohan2012 Avatar asked Jul 30 '11 00:07

xiaohan2012


1 Answers

Struts2-JSON plugin allows you to exclude null properties

<result type="json">
  <param name="excludeNullProperties">true</param>
</result>

or exclude certain parameters from being serialized

<result type="json">
  <param name="excludeProperties">
    login.password,
    studentList.*\.sin
  </param>
</result>

See documentation for more details

like image 178
nmc Avatar answered Nov 14 '22 22:11

nmc