@Override public JsonElement serialize(List<PortConfig> src, Type typeOfSrc, JsonSerializationContext context) { if (src.size() == 0) { return new JsonNull(); } JsonArray array = new JsonArray(); for (PortConfig pc : src) { array.add(s_gson.toJsonTree(pc)); } return array; }
@Override public JsonElement serialize(Pair<Long, Long> src, java.lang.reflect.Type typeOfSrc, JsonSerializationContext context) { JsonArray array = new JsonArray(); if (src.first() != null) { array.add(s_gson.toJsonTree(src.first())); } else { array.add(new JsonNull()); } if (src.second() != null) { array.add(s_gson.toJsonTree(src.second())); } else { array.add(new JsonNull()); } return array; }
break; case Null : JsonNull n = new JsonNull(); arr.add(n); map.put(n, lexer.location.copy());
break; case Null: JsonNull n = new JsonNull(); obj.add(itemName, n); map.put(n, lexer.location.copy());
break; case Null : JsonNull n = new JsonNull(); arr.add(n); if (map != null)
break; case Null: JsonNull n = new JsonNull(); obj.add(itemName, n); if (map != null)
@Override public JsonElement serialize(final List<PortConfig> src, final Type typeOfSrc, final JsonSerializationContext context) { if (src.size() == 0) { return new JsonNull(); } final JsonArray array = new JsonArray(); for (final PortConfig pc : src) { array.add(s_gson.toJsonTree(pc)); } return array; }
@Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { if (src == null) { return new JsonNull(); } return new JsonPrimitive(JSDateUtils.toNormalizedString(src)); }
@Override public JsonElement serialize(final EIURI uri, final Type type, final JsonSerializationContext context) { if ( uri == null ) { return new JsonNull(); } return new JsonPrimitive( uri.toString() ); }
public static JsonObject map(Map<String, Object> map) { JsonObject ret = new JsonObject(); Set<Entry<String, Object>> entries = map.entrySet(); for (Entry<String, Object> entry : entries) { String key = entry.getKey(); Object v = entry.getValue(); if (v == null) { v = new JsonNull(); } if (!(v instanceof JsonElement)) { v = JsonUtil.createBasic(v); } ret.add(key, (JsonElement) v); } return ret; }
@SuppressWarnings("unchecked") @Override public JsonElement serialize(Map<?, ?> map, Type typeOfSrc, JsonSerializationContext ctx) { if (map == null) { return new JsonNull(); } JsonObject js = new JsonObject(); for (Object k : map) { js.add(k.toString(), ctx.serialize(((Map) map).$get(k.toString()))); } return js; }
public static JsonObject create(Object... values) { if (values.length % 2 != 0) { throw new RuntimeException("invalid length"); } JsonObject ret = new JsonObject(); for (int i = 0; i < values.length; i += 2) { String name = (String) values[i]; Object value = values[i + 1]; if (value == null) { value = new JsonNull(); } if (!(value instanceof JsonElement)) { value = JsonUtil.createBasic(value); } ret.add(name, (JsonElement) value); } return ret; }
@SuppressWarnings("unchecked") public static JsonElement createBasic(Object value) { if (value == null) { return new JsonNull(); } if (value instanceof Boolean) { return new JsonPrimitive(((Boolean) value)); } if (value instanceof Number) { return new JsonPrimitive((Number) value); } if (value instanceof String) { return new JsonPrimitive((String) value); } if (value instanceof Iterable) { Iterable<Object> it = (Iterable<Object>) value; JsonArray ret = new JsonArray(); for (Object object : it) { ret.add(createBasic(object)); } return ret; } throw new UnsupportedOperationException("unsupported type: " + value); }
@Override public JsonElement serialize(final Pair<Long, Long> src, final java.lang.reflect.Type typeOfSrc, final JsonSerializationContext context) { final JsonArray array = new JsonArray(); if (src.first() != null) { array.add(s_gson.toJsonTree(src.first())); } else { array.add(new JsonNull()); } if (src.second() != null) { array.add(s_gson.toJsonTree(src.second())); } else { array.add(new JsonNull()); } return array; }
@Override public JsonElement serialize(Array<?> array, Type type, JsonSerializationContext ctx) { if (array == null) { return new JsonNull(); } JsonArray js = new JsonArray(); // validate that we have a packed array (no unset elements) and that we do not // have any non-array indices. JSON supports none of these features, and toList() // detects them and rejects them too. List<?> list = array.toList(); return ctx.serialize(list); }
private JsonElement asJsonValue(Object value) { if (value == null) { return new JsonNull(); } else if (value.getClass().isArray()) { Object[] arr = (Object[]) value; JsonArray retval = new JsonArray(); for (Object sub : arr) { retval.add(asJsonValue(sub)); } return retval; } else if (value instanceof Boolean) { return new JsonPrimitive((Boolean) value); } else if (value instanceof Number) { return new JsonPrimitive((Number) value); } else if (value instanceof String) { return new JsonPrimitive((String) value); } else { Map<String, Object> retval = new HashMap<String, Object>(); Field[] fields = value.getClass().getFields(); for (Field field : fields) { try { Object subVal = PropertyUtils.getProperty(value, field.getName()); retval.put(field.getName(), subVal); } catch (Exception e) { retval.put(field.getName(), null); } } return toJsonObject(retval); } }
return new JsonNull();
break; case Null : JsonNull n = new JsonNull(); arr.add(n); map.put(n, lexer.location.copy());
break; case Null : JsonNull n = new JsonNull(); arr.add(n); map.put(n, lexer.location.copy());
break; case Null : JsonNull n = new JsonNull(); arr.add(n); map.put(n, lexer.location.copy());