In an Struts 2 project, we need to serialize and deserialize objects, as our requirement is very simple, we decide to use Struts 2 JSONUtil instead of gson.
import org.apache.struts2.json;
String json = JSONUtil.serialize(myAccountVO);
// return: {"accountNumber":"0105069413007","amount":"1500","balance":"215000"}
For deserialization, we face the class cast exception
AccountVO vo =(AccountVO) JSONUtil.deserialize(json);
//Exception
I find that the deserialization returns a map with key value of object properties. So I must do as:
HashMap<String,String> map = (HashMap) JSONUtil.deserialize(string)
accountVo.setAccountNumber(map.get("accountNumber"));
....
Well can I do it better or I am expecting too much from this utility.