On the basis of your statement as follows:
You should *very* rarely need to write custom encoders/decoders, DJN takes care of everything 99% of the time.
I have tested serialization and deserialization between json and java with some complex json object, but I found that it was not done automatically and I have to write code by iterating json object and assigning corresponding values to java object. Followings are the codes:
Javascript code:
Code:
Ext.onReady(function(){
var aDate = {year: 2005, month: 3, day: 20};
var userJson = {name: 'Jitendra', age: 3, city: 'Delhi'};
var companies = [
{
"id": "17",
"name": "Emkay Entertainments",
"address": "Nobel House, Regent Centre",
"manager": {
"firstName": "John",
"lastName": "Doe"
},
"employees": [ {
"firstName": "Brian",
"lastName": "Hunt"
},
{
"firstName": "Mick",
"lastName": "Henning"
}
]
},
{
"id": "18",
"name": "The Empire",
"address": "Milton Keynes Leisure Plaza",
"manager": {
"firstName": "Ana",
"lastName": "Johnsnon"
},
"employees": [
{
"firstName": "Erick",
"lastName": "O'Neil"
},
{
"firstName": "George",
"lastName": "Halloway"
}
]
}
];
Ext.Direct.addProvider(
Ext.app.REMOTING_API
);
//testing with custom hierarchical json object for serialization and deserialization
CompanyAction.getCompanyDetail(companies, function(result, e) {
var t = e.getTransaction();
alert(result.name);
});
CompanyAction.test("jks",null, function(result, e) {
var t = e.getTransaction();
});
});
Now the json object is having a company list and each company has a manager object and a list of employee object. following are my java classes:
1) CompanyAction.java --- exposed java class
Code:
package company;
import java.util.ArrayList;
import com.softwarementors.extjs.djn.config.annotations.DirectMethod;
public class CompanyAction {
@DirectMethod
public ArrayList<Company> getCompanyDetail(ArrayList<Company> companies){
if(companies.size()>0)
System.out.println("company name = "+companies.get(0).getName());
return companies;
}
@DirectMethod
public String test(String a, String b){
return "tested";
}
}
2) Company.java
Code:
package company;
import java.util.ArrayList;
public class Company {
private String id;
private String name;
private String address;
private Manager manager;
private ArrayList<Employee> employees;
// code for some getters and setters
}
3) Employee.java
Code:
package company;
public class Employee {
private String firstName;
private String lastName;
//code for getters and setters
}
4) Manager.java
Code:
package company;
public class Manager {
private String firstName;
private String lastName;
//code for getters and setters
}
Now, I have read your document and also done a lot of googling, but I didn't find any type of configuration between Json object attributes and Java class attributes in DJN so that the values of Json object attributes can be directly assigned to corresponding java class attributes. How does the DJN control will automatically decide that the value of first name of Manager attribute of Json object will be assigned to the First Name of Manager Java Object but not to that of Employee Java Object. I have done this by manually writing serialization deserialization code, but in DWR it can be done automatically by just some configuration
Actually, this issue has become a bottleneck in our evaluation process and due to this some of our team members are suggesting DWR as alternate solution.
So, please if there is any configuration based approach or annotation based approch to solve this issue, then suggest me.