In plovr, I created the utility SoyDataUtil.java , which takes JsonElement and converts it to SoyData . Admittedly, you can only find this if you are already using Gson , but the nice thing about this approach is that Gson will most likely take care to setter reflection for you. For example, I believe that you should do this:
JsonElement json = (new Gson()).toJsonTree(courses); SoyData soyData = SoyDataUtil.jsonToSoyData(json); Map<String, Object> params = new HashMap<String, Object>(); params.put("courses", soyData);
The trick is to use Gson for reflection in order to turn courses into JsonElement . Not sure if you want to add these dependencies (although the code from plovr is pretty small - you can just copy it directly), but this may be the most appropriate solution.
source share