当前位置: 首页>>代码示例>>Java>>正文


Java TypeUtils.castToJavaBean方法代码示例

本文整理汇总了Java中com.alibaba.fastjson.util.TypeUtils.castToJavaBean方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.castToJavaBean方法的具体用法?Java TypeUtils.castToJavaBean怎么用?Java TypeUtils.castToJavaBean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.fastjson.util.TypeUtils的用法示例。


在下文中一共展示了TypeUtils.castToJavaBean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_bean_3

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_bean_3() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    PO vo = TypeUtils.castToJavaBean(map, PO.class);
    Assert.assertEquals(123, vo.id);
    
    SerializeWriter out = new SerializeWriter();

    try {
        SerializeConfig config = new SerializeConfig();
        JSONSerializer serializer = new JSONSerializer(out, config);
        config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", (String) null)));

        serializer.write(vo);

        Assert.assertEquals("{}", out.toString());
    } finally {
        out.close();
    }

    
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:TypeUtilsTest_castToJavaBean.java

示例2: test_bean_2

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_bean_2() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    PO vo = TypeUtils.castToJavaBean(map, PO.class);
    Assert.assertEquals(123, vo.id);
    
    SerializeWriter out = new SerializeWriter();

    try {
        SerializeConfig config = new SerializeConfig();
        JSONSerializer serializer = new JSONSerializer(out, config);
        config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", "ID")));

        serializer.write(vo);

        Assert.assertEquals("{\"ID\":123}", out.toString());
    } finally {
        out.close();
    }

    
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:TypeUtilsTest_castToJavaBean.java

示例3: getObject

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:JSONArray.java

示例4: test_castToJavaBean_StackTraceElement

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_castToJavaBean_StackTraceElement() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("className", "java.lang.Object");
    map.put("methodName", "hashCode");
    StackTraceElement element = TypeUtils.castToJavaBean(map, StackTraceElement.class, null);
    Assert.assertEquals("java.lang.Object", element.getClassName());
    Assert.assertEquals("hashCode", element.getMethodName());
    Assert.assertEquals(null, element.getFileName());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:TypeUtilsTest_castToJavaBean.java

示例5: test_castToJavaBean_StackTraceElement_1

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_castToJavaBean_StackTraceElement_1() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("className", "java.lang.Object");
    map.put("methodName", "hashCode");
    map.put("lineNumber", 12);
    StackTraceElement element = TypeUtils.castToJavaBean(map, StackTraceElement.class, null);
    Assert.assertEquals("java.lang.Object", element.getClassName());
    Assert.assertEquals("hashCode", element.getMethodName());
    Assert.assertEquals(null, element.getFileName());
    Assert.assertEquals(12, element.getLineNumber());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:TypeUtilsTest_castToJavaBean.java

示例6: test_castToJavaBean_type

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_castToJavaBean_type() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("@type", "java.lang.StackTraceElement");
    map.put("className", "java.lang.Object");
    map.put("methodName", "hashCode");
    map.put("lineNumber", 12);
    StackTraceElement element = (StackTraceElement) TypeUtils.castToJavaBean(map, Object.class, null);
    Assert.assertEquals("java.lang.Object", element.getClassName());
    Assert.assertEquals("hashCode", element.getMethodName());
    Assert.assertEquals(null, element.getFileName());
    Assert.assertEquals(12, element.getLineNumber());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:TypeUtilsTest_castToJavaBean.java

示例7: test_error

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_error() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("@type", "xxx");
    Exception error = null;
    try {
        TypeUtils.castToJavaBean(map, Object.class, null);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:TypeUtilsTest_castToJavaBean.java

示例8: test_error2

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_error2() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("@type", "");
    Exception error = null;
    try {
        TypeUtils.castToJavaBean(map, Object.class, null);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:TypeUtilsTest_castToJavaBean.java

示例9: test_bean

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_bean() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    Entity vo = TypeUtils.castToJavaBean(map, Entity.class);
    Assert.assertEquals(123, vo.getId());

    Assert.assertEquals("{\"id\":123}", JSON.toJSONString(vo));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:TypeUtilsTest_castToJavaBean.java

示例10: test_deny

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_deny() throws Exception {
    JSONObject object = new JSONObject();
    object.put("@type", "com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase");

    Throwable error = null;
    try {
        TypeUtils.castToJavaBean(object, Object.class);
    } catch (Exception ex) {
        error = ex;
    }
    assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DenyTest16.java

示例11: test_error

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_error() throws Exception {
    JSONObject json = new JSONObject();
    json.put("id", 1);

    JSONException error = null;
    try {
        TypeUtils.castToJavaBean(json, C.class, ParserConfig.getGlobalInstance());
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:TypeUtilsTest.java

示例12: test_castToJavaBean

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_castToJavaBean() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    map.put("name", "abc");
    VO vo = TypeUtils.castToJavaBean(map, VO.class, null);
    Assert.assertEquals(123, vo.getId());
    Assert.assertEquals("abc", vo.getName());
    
    Assert.assertEquals("{\"name\":\"abc\",\"id\":123}", JSON.toJSONString(vo));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:TypeUtilsTest_castToJavaBean_JSONType.java

示例13: test_castToJavaBean_v2

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_castToJavaBean_v2() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    map.put("name", "abc");
    V2 vo = TypeUtils.castToJavaBean(map, V2.class, null);
    Assert.assertEquals(123, vo.getId());
    Assert.assertEquals("abc", vo.getName());
    
    Assert.assertEquals("{\"name\":\"abc\",\"id\":123}", JSON.toJSONString(vo));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:TypeUtilsTest_castToJavaBean_JSONType.java

示例14: test_castToJavaBean_v3

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public void test_castToJavaBean_v3() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    map.put("name", "abc");
    V3 vo = TypeUtils.castToJavaBean(map, V3.class, null);
    Assert.assertEquals(123, vo.getId());
    Assert.assertEquals("abc", vo.getName());
    
    Assert.assertEquals("{\"name\":\"abc\",\"id\":123}", JSON.toJSONString(vo));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:TypeUtilsTest_castToJavaBean_JSONType.java

示例15: getObject

import com.alibaba.fastjson.util.TypeUtils; //导入方法依赖的package包/类
public <T> T getObject(String key, Class<T> clazz){
    Object obj = get(key);
    return TypeUtils.castToJavaBean(obj, clazz);
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:5,代码来源:JSONBean.java


注:本文中的com.alibaba.fastjson.util.TypeUtils.castToJavaBean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。