Author Topic: Convert getChanges array to java  (Read 2889 times)

stoodin

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 85
    • View Profile
Convert getChanges array to java
« on: June 01, 2014, 01:17:55 am »
Hi,
I am sending the updateList from the grid getChanges to my Controller.
In Controller I am getting the JSONArray and when I iterate I am getting a "String" object that is essentially the JSONArray again.
What is the most efficient way to get the "updateList" to java Map or something I can extract key/value in my Controller.
Thanks a lot for your help.
Just additional info: I am not using ajax calls but rather pass the updateList as hidden variable from the jsp page to the controller.
I see in debugger that I am getting a JSONArray which has String array inside that is formatted as the JSONArray too but I am not able to cast it to JSONArray. The exception thrown saying it is a String type and the format is "[{"key":"Value"}]. I can certainly parse it as string but looking for more efficient way to do that.
Thanks a lot,
« Last Edit: June 01, 2014, 05:55:25 pm by stoodin »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6260
    • View Profile
Re: Convert getChanges array to java
« Reply #1 on: June 02, 2014, 05:41:31 pm »
you could do it more conveniently by using a JSON library e.g., flexjson       


import flexjson.JSONSerializer;
import flexjson.JSONDeserializer;


JSONDeserializer<List<T>> deserializer = new JSONDeserializer<List<T>>();
List<T> updateListArray = deserializer.deserialize( updateListString );

where T is row class/entity

Please let me know if you need any further assistance.
« Last Edit: June 02, 2014, 06:50:28 pm by paramquery »

stoodin

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 85
    • View Profile
Re: Convert getChanges array to java
« Reply #2 on: June 02, 2014, 09:58:34 pm »
Thanks a lot Great Idea!
I made it work.

Thanks a lot. Your help is very valuable.
« Last Edit: June 03, 2014, 06:23:02 pm by stoodin »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6260
    • View Profile
Re: Convert getChanges array to java
« Reply #3 on: June 12, 2014, 08:42:19 am »
I'm glad you made it work.

Server side scripts for java ( spring framework ) have been added in the demos under java tab.

Particular code of relevance to your question (for anyone reading this post):

JSONDeserializer<List<T>> deserializer = new JSONDeserializer<List<T>>();
List<T> list = deserializer.use( "values", T.class ).deserialize(str);