Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Warning

This page is DEPRECATED, please refer to the new source http://struts.apache.org/plugins/json/

 

Table of Contents

The JSON plugin

Excerpt

provides a "json" result type that serializes actions into JSON

. The serialization process is recursive, meaning that the whole object graph, starting on the action class (base class not included) will be serialized (root object can be customized using the "root" attribute). If the interceptor is used, the action will be populated from the JSON content in the request, these are the rules of the interceptor:

...

Note

root attribute must be set on the JSONInterceptor when dealing with JSON array.

Tip

This plugin also provides AJAX Validation.

Installation

This plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib directory. No other files need to be copied or created.

...

Code Block
@InterceptorRef(value="json")

By default Content-Type of value application/json is recognised to be used for de-serialisation and application/json-rpc to execute SMD processing. You can override those settings be defining jsonContentType and jsonRpcContentType params, see example:

Code Block
xml
xml
<interceptor-ref name="json">
  <param name="jsonContentType">text/json</param>
  <param name="jsonRpcContentType">text/json-rpc</param>
</interceptor-ref>

Please be aware that those are scoped params per stack, which means, once set it will be used by actions in scope of this stack.

JSON RPC

The json plugin can be used to execute action methods from javascript and return the output. This feature was developed with Dojo in mind, so it uses Simple Method Definition to advertise the remote service. Let's work it out with an example(useless as most examples).

...