Sending JSON/Array Object to backend

393 views
Skip to first unread message

leifg

unread,
Apr 9, 2010, 6:22:50 PM4/9/10
to play-framework
Hello everyone,

I try to send a a serlialized array using the jQuery method
serializeArray(). Afterwards I send an Ajax "PUT" request to the
according URL.

like this:

var data = $("#createForm").serializeArray();
$.ajax({
type: "PUT",
url: "http://localhost:9000/leifg",
data: data
});

I can debug in the backend method public static void createJson(String
screenName, String data), but the String variable data is null.

If I change the signature to public static void createJson(String
screenName, HashMap<String, String> data), I will just get an empty
HashMap.

In the debug mode, I can see, that there is a HashMap inside the
params variable called "data" which contains all the data from the
form.

My question now is:
- how can I access this Hashmap (params.get("data", HashMap.class);
didn't work)?
- is there a better way to deal with JSON/String-Arrays in the play!
backend?

Guillaume Bort

unread,
Apr 10, 2010, 6:11:58 AM4/10/10
to play-fr...@googlegroups.com
Can you show me what the data Javascript object looks like?

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

leifg

unread,
Apr 10, 2010, 2:16:31 PM4/10/10
to play-framework
OK so the frontend delivers an object array (i made a screenshot,
since i found no easy way to dump the data into a single string):
http://dl.dropbox.com/u/6253/object_array.png

In the java backend I get the variable data, which is a HashMap and
looks something like this:

{body=[Ljava.lang.String;@31133976,
tweetSpanEnd=[Ljava.lang.String;@65218b25,
queueType=[Ljava.lang.String;@7d365e01,
screenName=[Ljava.lang.String;@78189538,
queueName=[Ljava.lang.String;@7c55d3df,
queueDescription=[Ljava.lang.String;@66c9153e,
tweetSpanStart=[Ljava.lang.String;@1b91ce2a,
queueInterval=[Ljava.lang.String;@176358a,
tweetSpanEnabled=[Ljava.lang.String;@77b4f7c5}

regards
leif

Guillaume Bort

unread,
Apr 11, 2010, 2:13:01 PM4/11/10
to play-fr...@googlegroups.com
Ok so it is very complicated to have this stuff bound automatically.

My advice:

public static void yop(String body) {
// here body contains the json string
// use GSON to parse it dynamically

Reply all
Reply to author
Forward
0 new messages