How to return json data selectively in struts2 action class

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

These properties do not perform the same task. In fact, they respond to different requests for business services or are associated with various actions.

And my problem is this:

I need to filter the data and return only a part of the properties within the set of properties, because not all properties are needed in one request (action).

PS: Actually, I could divide these actions or business logic into several classes instead of putting them in one class of actions. However, I think they all share similar DAOs and services, so I put them together to prevent redundant IOCs.

+4
source share
1 answer

Struts2-JSON plugin eliminates null properties

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

or exclude some options from serialization

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

See more details.

+11
source

All Articles