Daler Daler - 1 year ago 144
Java Question

Incompatible types for property setData [JSON+Struts2 plugin]

I need to configure JSON Plugin (https://struts.apache.org/docs/json-plugin.html) with my current JAVA web application. What I've done:

1) Added to

file all dependencies for the plugin.


2) Extended the package in struts.xml with

<package name="my-test-package" extends="xxx, json-default"

3) Added to my action the interceptor and result type of json

<action name="myMainAction"
<interceptor-ref name="json">
<param name="enableSMD">true</param>
<result type="json">
<param name="requiredAuthorities">F_ADD</param>

4) Created a Model class
with only setters/getters in it.

5) Created the Action class, named as
with following code

private List <Marriage> data;

public List<Marriage> getData() {
return data;
public void setData(List<Marriage> data) {
System.out.println("Inside the setter ");
this.data = data;

public String execute() throws Exception {


return SUCCESS;

6) Created a
object and passed it via
to the server. I can see through Google Chrome Console, that it sends the data and it does parse the JSON object and all data is in there. However, it does throw an exception in my Eclipse and also in Chrome Console:

Exception occurred during processing request: Incompatible types for property setData (CommonsLogger.java [qtp1144623021-22])
org.apache.struts2.json.JSONException: Incompatible types for property setData

Could you please point me to some right direction, it's almost the second day which i'm working on it but it doesn't seem to start working.

The data which is being sent to java side and I can see it via Chrome console.


This is the object after it has been
As you can see it has the root
variable and then all the rest of the data goes under it. According to my logic ti has to find the
of the data in my java class and then call the setters/getters of that class.
P.S I renamed the name of the classes and etc so no worries about naming conventions) I do have the right things on my production code.


Thanks for pointing out to my mistake @AleksandrM. Now It throws a very strange error:

Unparseable date: "20-07-2016" (CommonsLogger.java [qtp212900572-17])
java.text.ParseException: Unparseable date: "20-07-2016"

variable for this part is
and its implementation in JAVA:

private Date registrationDate;
public Date getRegistrationDate() {
return registrationDate;

public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;

As I understand it tries to set a
and it can't do it. Why the json-plugin can't convert it? Should I write something in the options/settings?

Answer Source

You are expecting List<Marriage> data in the Java code but your JSON object doesn't hold any array. Either change Java code to Marriage data or post array of objects in JSON.

You may also want to define other interceptors, besides json, for the action. Create custom interceptor stack and reference it in your action configuration.

<interceptor-stack name="json-stack">
    <interceptor-ref name="json" />
    <interceptor-ref name="defaultStack" />

For the date string to Date object conversion use default format (probably yyyy-MM-dd) or create a custom Struts type converter.

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