Skip to content

Instantly share code, notes, and snippets.

@pcdinh
Created October 26, 2009 04:28
Show Gist options
  • Save pcdinh/218421 to your computer and use it in GitHub Desktop.
Save pcdinh/218421 to your computer and use it in GitHub Desktop.
package net.phpvietnam.clipsearch.utils;
import net.phpvietnam.clipsearch.domain.Clip;
import java.util.Map;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* An utility class to convert a <code>List</code> or <code>Map</code> object to a JSON string.
*
* @since October 12, 2009
* @author pcdinh
* @see http://json-lib.sourceforge.net/
*/
public class JsonUtils {
public static String convert(List<Clip> rs) {
JSONArray json = JSONArray.fromObject(rs);
return json.toString();
}
public static String convert(Map<String, Clip> rs) {
JSONObject json = JSONObject.fromObject(rs);
return json.toString();
}
public static String convert(Object rs) {
JSONObject json = JSONObject.fromObject(rs);
return json.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment