Utilizing DWR for AJAX calls in my project involves the conversion of JavaScript objects to Java objects by analyzing the Java class. My goal is to send and receive a JSON-like structure through DWR.
For example:
JavaScript Object:
{
"name" : "TamilVendhan",
"age" : "24",
"hobbies" : [
"gaming",
"gaming",
"gaming"
],
"address" : {
"doorNo" : "122",
"city" : "Banglore",
"state" : "Karnataka",
"country" : "india"
}
}
The above JavaScript object could be transformed into Java with the following code:
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "TamilVendhan");
map.put("age", "24");
List<String> list = new ArrayList<String>();
list.add("gaming");
list.add("gaming");
list.add("gaming");
map.put("hobbies", list);
Map<String, Object> addr = new HashMap<String, Object>();
addr.put("doorNo",122);
addr.put("city", "banglore");
addr.put("state", "Karnataka");
addr.put("country", "India");
map.put("address", addr);
I am curious if it's feasible to achieve this conversion using DWR. If so, any guidance would be appreciated!
Thank you!
Update:
It is indeed possible to convert JavaScript objects into Map<String, Object>
using DWR. However, this conversion only works for one level. In cases where there are nested objects or arrays, it may result in a conversion error
.
Refer to this ticket for more information.