Laxmikanth Samudrala Laxmikanth Samudrala - 2 years ago 74
Java Question

Action to accept dynamic json data from user interface

I would like to have an

class which should accept a JSON string constructed from user interface with no setter and getter in the

Is it possible? If so, what conventions would I need to follow in
class and in configuration files (

Answer Source

Post them as content with type "application/json". You may do it with a simple jquery ajax call where you could specify the content-type and dataType.

   type: "POST",
   url: "/the/action/url",     
   data : {},
   contentType: "application/json; charset=utf-8"

Add json plugin to the project dependencies with json-lib-2.3-jdk15.jar. The plugin supplied with the interceptor json that reads and populates an action from the request. If you don't want to populate the action then you should not use this interceptor. Instead manually parse the request with this or any other third party library to get the JSONObject. Or you could rewrite the interceptor and comment that code that is using JSONPopulator but deserialize the object with JSONUtil.

Also, you might find this examples useful when manually creating/parsing JSON data.

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