开发者

java json controller

I have an Java class, like Library, that contains many fields. I want do ajax call to server and in controller's method I want to have partly initialized @RequestBody Library with only fields, which are present in json object.

I read 开发者_如何学Gothe http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/, but I need not full object.

Please Help


You could use a org.codehaus.jettison.json.JSONObject (part of the Jettison project) and only include the fields that you need. Or, you could just make a simplified version of Library that includes only the fields that you want (call it AjaxLibrary or something).


It would not be a problem to use full object, cause fields would not be initialized, if they are not present at entire json.

Also you can create own DTO class, e.g. SomeActionLibraryDTO. Extract required fields from Library, and use @JsonIgnoreProperties(ignoreUnknown = true) annotation for class to ignore the rest of json object (I suppose you are using the default json jackson marshaller, right?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜