xiaohan2012 xiaohan2012 - 1 year ago 57
JSON Question

Transfer only a part of properties in a class in struts' json

Sorry, I really don't know how to summarize the title of this question. So, the title may not be clear.

I have an action class which performs some business logic.

in the Action Class:

class ActionClass extends ActionSupport{
private Merchandise merchandise;// I want to transfer it to the client
//setter and getter


in the Merchandise class:

class Merchandise{
private String name; // I want to transfer it
private String price; //I don't want to transfer it
private String description;//I don't want to transfer it
//setter and getter

Now, I need to transfer the merchandise property in ActionClass to the client.

However, in the merchandise property, I want to transfer only the name property while inhibiting the other two properties.

Then how to inhibit the transfer of the other two properties(price and description) in class Merchandise?

nmc nmc
Answer Source

Try something like:

<!-- Result fragment -->
<result type="json">
  <param name="root">merchandise</param>
  <param name="excludeProperties">price,description</param>

See full documentation, other options and examples at http://struts.apache.org/2.2.3/docs/json-plugin.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download