把JSON字符串解释为对象结构。

@param <T> API响应类型
@param json JSON字符串
@param clazz API响应类
@return API响应对象
967697
public static <T extends AlipayResponse> T parseResponse(String json, Class<T> clazz)
                                                                                         throws AlipayApiException {
        ObjectJsonParser<T> parser = new ObjectJsonParser<T>(clazz);
        return parser.parse(json);
    }
1017948
@SuppressWarnings("unchecked")
    public static Map<String, Object> toMap(String json) {
        return (Map<String, Object>) JSON.parse(json);
    }
1010363
@SuppressWarnings("unchecked")
    @Override
    public final <T> T deserialize(byte[] content, Class<T> clazz) throws SerializerException {
        if (byte[].class.equals(clazz)) {
            return (T) content;
        }
        throw new SerializerException("Unable to deserialize to type '" + clazz.getName() + "'");
    }
1286397
@SuppressWarnings("unchecked")
    @Override
    public <T extends Object> T fetchObject(Class<T> clazz, String id) {
        if (StringUtils.isEmpty(id)) {
            return null;
        }
        
        String json = VistAUtil.getBrokerSession().callRPC("RGSER FETCH", PREFIX + getAlias(clazz), id);
        return (T) JSONUtil.deserialize(json);
    }
1008596
public String format(String json) {
        String result = null;
        if (json != null){
            if (json.startsWith("{")) {
                result = new JSONObject(json).toString(4);
            } else if (json.startsWith("[")) {
                JSONObject jsonObject = new JSONObject("{'a': " + json + "}");
                org.json.JSONArray array = (org.json.JSONArray) jsonObject.get("a");
                result = array.toString(4);
            }
        }
        return result;
    }
784504
@SuppressWarnings("unchecked")
  public <T> T get(String key, Class<T> clazz) {
    return (T) datas.get(key);
  }
932968
public static <T extends BasicMessage> T fromJSON(String json, Class<T> clazz) {
        try {
            Method buildObjectMapperForDeserializationMethod = findBuildObjectMapperForDeserializationMethod(clazz);

            final ObjectMapper mapper = (ObjectMapper) buildObjectMapperForDeserializationMethod.invoke(null);
            if (FailOnUnknownProperties.class.isAssignableFrom(clazz)) {
                mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
            }

            return mapper.readValue(json, clazz);
        } catch (Exception e) {
            throw new IllegalStateException("JSON message cannot be converted to object of type [" + clazz + "]", e);
        }
    }
1183190
public static Parameters fromJson(String json) {
		Map<String, Object> map = JsonConverter.toNullableMap(json);
		return map != null ? new Parameters(map) : new Parameters();
	}
1164602
public <T> T fromJson(final Map<?, ?> json, Class<T> clazz) throws AlipayApiException {
        return Converters.convert(clazz, new Reader() {
            public boolean hasReturnField(Object name) {
                return json.containsKey(name);
            }

            public Object getPrimitiveObject(Object name) {
                return json.get(name);
            }

            public Object getObject(Object name, Class<?> type) throws AlipayApiException {
                Object tmp = json.get(name);
                if (tmp instanceof Map<?, ?>) {
                    Map<?, ?> map = (Map<?, ?>) tmp;
                    return fromJson(map, type);
                } else {
                    return null;
                }
            }

            public List<?> getListObjects(Object listName, Object itemName, Class<?> subType)
                                                                                             throws AlipayApiException {
                List<Object> listObjs = null;

                Object listTmp = json.get(listName);
                if (listTmp instanceof Map<?, ?>) {
                    Map<?, ?> jsonMap = (Map<?, ?>) listTmp;
                    Object itemTmp = jsonMap.get(itemName);
                    if (itemTmp == null && listName != null) {
                        String listNameStr = listName.toString();
                        itemTmp = jsonMap.get(listNameStr.substring(0, listNameStr.length() - 1));
                    }
                    if (itemTmp instanceof List<?>) {
                        listObjs = getListObjectsInner(subType, itemTmp);
                    }
                } else if (listTmp instanceof List<?>) {
                    listObjs = getListObjectsInner(subType, listTmp);
                }

                return listObjs;
            }

            private List<Object> getListObjectsInner(Class<?> subType, Object itemTmp)
                                                                                      throws AlipayApiException {
                List<Object> listObjs;
                listObjs = new ArrayList<Object>();
                List<?> tmpList = (List<?>) itemTmp;
                for (Object subTmp : tmpList) {
                    Object obj = null;
                    if (String.class.isAssignableFrom(subType)) {
                        obj = subTmp;
                    } else if (Long.class.isAssignableFrom(subType)) {
                        obj = subTmp;
                    } else if (Integer.class.isAssignableFrom(subType)) {
                        obj = subTmp;
                    } else if (Boolean.class.isAssignableFrom(subType)) {
                        obj = subTmp;
                    } else if (Date.class.isAssignableFrom(subType)) {
                        DateFormat format = new SimpleDateFormat(AlipayConstants.DATE_TIME_FORMAT);
                        try {
                            obj = format.parse(String.valueOf(subTmp));
                        } catch (ParseException e) {
                            throw new AlipayApiException(e);
                        }
                    } else if (subTmp instanceof Map<?, ?>) {// object
                        Map<?, ?> subMap = (Map<?, ?>) subTmp;
                        obj = fromJson(subMap, subType);
                    }

                    if (obj != null) {
                        listObjs.add(obj);
                    }
                }
                return listObjs;
            }

        });
    }
25032
public <T> T toObject(String jsonString, Class<T> clazz) {
		if (StringUtils.isEmpty(jsonString)) {
			return null;
		}

		try {
			return mapper.readValue(jsonString, clazz);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
123101
public <T> T parse(JsonObject obj, Class<T> clazz) {
        return gson.fromJson(obj, clazz);
    }
28740
public static <T extends Serializable> T deserializeObject( byte[] bytes, Class<T> clazz )
	throws IOException, ClassNotFoundException {

		ByteArrayInputStream is = new ByteArrayInputStream( bytes );
		ObjectInputStream deserializer = new ObjectInputStream( is );
		return clazz.cast( deserializer.readObject());
	}
86499
public static Option fromJSON(String json) {
        Gson gson = new GsonBuilder().setPrettyPrinting().
                registerTypeAdapter(Series.class, new SeriesDeserializer()).
                registerTypeAdapter(Axis.class, new AxisDeserializer()).create();
        Option option = gson.fromJson(json, Option.class);
        return option;
    }
170537
@Deprecated
    public static <T> T buildJsonResponse(Response response, Class<T> clazz) throws IOException, SlackApiException {
        if (response.code() == 200) {
            String body = response.body().string();
            DETAILED_LOGGER.accept(new HttpResponseListener.State(SlackConfig.DEFAULT, response, body));
            return GsonFactory.createSnakeCase().fromJson(body, clazz);
        } else {
            String body = response.body().string();
            throw new SlackApiException(response, body);
        }
    }
76226
public <T> T fromJson(@Nullable String jsonString, Class<T> clazz) {
		if (StringUtils.isEmpty(jsonString)) {
			return null;
		}

		try {
			return mapper.readValue(jsonString, clazz);
		} catch (IOException e) {
			logger.warn("parse json string error:" + jsonString, e);
			return null;
		}
	}
405956
public static OptimizationConfiguration fromYaml(String json) {
        try {
            return JsonMapper.getYamlMapper().readValue(json, OptimizationConfiguration.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
491274
static SearchBuilder fromJson(String json) {
        try {
            return JsonSerializer.fromString(json, SearchBuilderLegacy.class).builder;
        } catch (IOException e) {
            throw new IndexException(e, "Unparseable JSON search: {}", json);
        }
    }