Java Code Examples for com.alibaba.fastjson.util.TypeUtils#castToJavaBean()

The following examples show how to use com.alibaba.fastjson.util.TypeUtils#castToJavaBean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONArray.java    From uavstack with Apache License 2.0 5 votes vote down vote up
public <T> T getObject(int index, Type type) {
    Object obj = list.get(index);
    if (type instanceof Class) {
        return (T) TypeUtils.castToJavaBean(obj, (Class) type);
    } else {
        String json = JSON.toJSONString(obj);
        return (T) JSON.parseObject(json, type);
    }
}
 
Example 2
Source File: JSONObject.java    From uavstack with Apache License 2.0 4 votes vote down vote up
public <T> T getObject(String key, Class<T> clazz) {
    Object obj = map.get(key);
    return TypeUtils.castToJavaBean(obj, clazz);
}
 
Example 3
Source File: JSONArray.java    From uavstack with Apache License 2.0 4 votes vote down vote up
public <T> T getObject(int index, Class<T> clazz) {
    Object obj = list.get(index);
    return TypeUtils.castToJavaBean(obj, clazz);
}