| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.shindig.social.core.util; |
| 19 | |
|
| 20 | |
import org.apache.commons.logging.Log; |
| 21 | |
import org.apache.commons.logging.LogFactory; |
| 22 | |
|
| 23 | |
import java.util.Map.Entry; |
| 24 | |
|
| 25 | |
import net.sf.json.JSONArray; |
| 26 | |
import net.sf.json.JSONObject; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | 0 | public final class JsonLibConverterUtils { |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 1 | protected static final Log LOG = LogFactory.getLog(JsonLibConverterUtils.class); |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public static final void dumpJsonObject(JSONObject jsonObject, String indent) { |
| 47 | 6 | for (Object o : jsonObject.entrySet()) { |
| 48 | 9 | Entry<?, ?> entry = (Entry<?, ?>) o; |
| 49 | 9 | Object key = entry.getKey(); |
| 50 | 9 | Object value = entry.getValue(); |
| 51 | 9 | if (value instanceof JSONObject) { |
| 52 | 3 | LOG.info(indent + key + ":JSONObject"); |
| 53 | 3 | dumpJsonObject((JSONObject) value, indent + " "); |
| 54 | 3 | } else if (value instanceof JSONArray) { |
| 55 | 3 | LOG.info(indent + key + ":JSONArray " + ((JSONArray) value).size()); |
| 56 | 3 | dumpJsonArray((JSONArray) value, indent + " "); |
| 57 | 3 | } else { |
| 58 | 3 | if (value == null) { |
| 59 | 0 | LOG.info(indent + key + ":null:na"); |
| 60 | 0 | } else { |
| 61 | 3 | LOG.info(indent + key + ":" + value + ":" + value.getClass()); |
| 62 | |
} |
| 63 | |
} |
| 64 | 9 | } |
| 65 | 6 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public static void dumpJsonArray(JSONArray array, String indent) { |
| 73 | 5 | for (Object value : array) { |
| 74 | 2 | if (value instanceof JSONObject) { |
| 75 | 2 | LOG.info(indent + ":JSONObject"); |
| 76 | 2 | dumpJsonObject((JSONObject) value, indent + " "); |
| 77 | 2 | } else if (value instanceof JSONArray) { |
| 78 | 0 | LOG.info(indent + ":JSONArray " + ((JSONArray) value).size()); |
| 79 | 0 | dumpJsonArray((JSONArray) value, indent + " "); |
| 80 | 0 | } else { |
| 81 | 0 | LOG.info(indent + ":" + value + ":" + (value == null ? "na" : value.getClass())); |
| 82 | |
} |
| 83 | 2 | } |
| 84 | 5 | } |
| 85 | |
} |