开发者

Json Entity List with Play Framework

I try to run this code but I get a NULL exception.

Java Code :

public static void updateData(List<Users> users){
 开发者_Go百科  for(Users u : users){ //Erros
      System.out.println(u.name); // Error
   }
}

Extjs Code :

proxy: {
    type: 'ajax',

    api: {
        update: '/Application/updateData'
    },
    reader: {
        type: 'json',
        root: 'users',
        successProperty: 'success'
    }
}    

Json Array :

[{"name":"Ed","email":"aa@aa.com"},{"name":"Ez","email":"bb@bb.com"}]

Please tell me how to bind a JSON array to an Entity List on Play Framework 1.2.2.


If you change the parameter of your method to body you are able to read the entire JSON string:

public static void updateData(String body){

I then use GSON (Play! uses the same lib) to deserialize the JSON response, example:

Gson gson = new Gson();
User user = gson.fromJson(body, User.class);

For me it works fine, but this might not be the best way, I'm not sure.

Cheers.

EDIT: I just saw that your ExtJS is returning 1 object wrapped in a array, if you always return ONE object no need for array so add to your ExtJS code (if you use ExtJS 4):

allowSingle: false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜