private static JSONObject fromTagToJson2(Tag tag) throws JSONException {
   JSONObject retval = new JSONObject();
   retval.put("guid", toString(tag.getTagGUID()));
   retval.put("type", toString(tag.getTagType()));
   retval.put("name", tag.getName());
   retval.put("contentsCount", tag.getContentsCount());
   return retval;
 }
 public static JSONObject fromTagToJson(Tag tag) {
   if (tag == null) {
     return null;
   }
   try {
     Class<?> clazz = tag.getClass();
     if (clazz == EventTag.class) {
       return fromEventTagToJson((EventTag) tag);
     } else if (clazz == FavoriteTag.class) {
       return fromFavoriteTagToJson((FavoriteTag) tag);
     } else if (clazz == PersonTag.class) {
       return fromPersonTagToJson((PersonTag) tag);
     } else if (clazz == PlacementTag.class) {
       return fromPlacementTagToJson((PlacementTag) tag);
     } else if (clazz == YearMonthTag.class) {
       return fromYearMonthTagToJson((YearMonthTag) tag);
     } else {
       throw new RuntimeException(String.format("Unknown class: %s", clazz.getName()));
     }
   } catch (Exception e) {
     Log.e("MiscUtils", "exception raised", e);
     return null;
   }
 }