java - Struts2 + Json Serialization of items -
i have following classes:
public class student { private long id ; private string firstname; private string lastname; private set<enrollment> enroll = new hashset<enrollment>(); //setters , getters } public class enrollment { private student student; private course course; long enrollid; //setters , getters }
i have struts2 controller , to return serialized instance of class student only.
@parentpackage("json-default") public class jsonaction extends actionsupport{ private student student; @autowired dbservice dbservice; public string populate(){ return "populate"; } @action(value="/getjson", results = { @result(name="success", type="json")}) public string test(){ student = dbservice.getsudent(new long(1)); return "success"; } @json(name="student") public student getstudent() { return student; } public void setstudent(student student) { this.student = student; } }
it returns me serializable student object sub classes, have student object without hashset returned . how can tell struts serialize object? have lazy loading enabled , hashset returned proxy class.
see answer here shows use of include , exclude properties. don't think example shows excluding nested objects have used purpose. if still have issues i'll post regex demonstrate this.
problem json plugin in struts 2
edit: here example of using exclude properties in annotation blocks serialization of nested member:
@parentpackage("json-default") @result(type = "json", params = { "excludeproperties", "^inventoryhistory\\[\\d+\\]\\.intrnmst, selectedtransactionnames, transactionnames" }) public class inventoryhistoryaction extends actionsupport { ...
inventoryhistory of type inventoryhistory jpa entity object, intrnmst references table because of lazy loading if serialized cause exception when action json serialized reason exclude parameter has been added prevent this.
note
\\
is required each \ character, single \ used in xml 2 required because of escaping string parsed right.
Comments
Post a Comment