Skip to content

Instantly share code, notes, and snippets.

@searls
Created April 21, 2011 18:32
Show Gist options
  • Save searls/935184 to your computer and use it in GitHub Desktop.
Save searls/935184 to your computer and use it in GitHub Desktop.
Mapping Java to JSON in a jdk1.4 compatible way
public String convert(List<Map<String, Object>> queryResults) {
//json-simple - WINNAR!
return JSONValue.toJSONString(queryResults);
//flexjson - fail - requires java.lang.Enum
// return new JSONSerializer().serialize(queryResults);
//Jackson - fail - requires java.io.Closeable
// try {
// return new ObjectMapper().writeValueAsString(queryResults);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
//Gson - fail - requires java.lang.reflect.Type
// return new Gson().toJson(queryResults);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment