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


Java JavaBeanSerializer类代码示例

本文整理汇总了Java中com.alibaba.fastjson.serializer.JavaBeanSerializer的典型用法代码示例。如果您正苦于以下问题:Java JavaBeanSerializer类的具体用法?Java JavaBeanSerializer怎么用?Java JavaBeanSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getPropertyValues

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Collection<Object> getPropertyValues(final Object currentObject) {
    final Class<?> currentClass = currentObject.getClass();

    JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentClass);

    if (beanSerializer != null) {
        try {
            return beanSerializer.getFieldValues(currentObject);
        } catch (Exception e) {
            throw new JSONPathException("jsonpath error, path " + path, e);
        }
    }

    if (currentObject instanceof Map) {
        Map map = (Map) currentObject;
        return map.values();
    }

    throw new UnsupportedOperationException();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:JSONPath.java

示例2: test_bean_2

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的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: test_bean_3

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的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

示例4: test_0

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_0() throws Exception {
    User user = new User();
    user.setId(123);
    user.setName("毛头");

    SerializeConfig mapping = new SerializeConfig();
    mapping.put(User.class, new JavaBeanSerializer(User.class, "id"));

    JSONSerializer serializer = new JSONSerializer(mapping);
    serializer.write(user);
    String jsonString = serializer.toString();

    Assert.assertEquals("{\"id\":123}", jsonString);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSON_toJSONStringTest.java

示例5: test_1

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_1() throws Exception {
    User user = new User();
    user.setId(123);
    user.setName("毛头");

    SerializeConfig mapping = new SerializeConfig();
    mapping.put(User.class, new JavaBeanSerializer(User.class, Collections.singletonMap("id", "uid")));

    JSONSerializer serializer = new JSONSerializer(mapping);
    serializer.write(user);
    String jsonString = serializer.toString();

    Assert.assertEquals("{\"uid\":123}", jsonString);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSON_toJSONStringTest.java

示例6: test_0_s

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_0_s() throws Exception {
    SerializeWriter out = new SerializeWriter();

    A a = new A();
    a.getL0().add("A");
    a.getL0().add("B");

    JavaBeanSerializer serializer = new JavaBeanSerializer(A.class);
    serializer.write(new JSONSerializer(out), a, null, null, 0);

    Assert.assertEquals("{\"l0\":[\"A\",\"B\"]}", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JavaBeanSerializerTest.java

示例7: test_1_s

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_1_s() throws Exception {
    SerializeWriter out = new SerializeWriter();

    B a = new B();
    a.getL0().add("A");
    a.getL0().add("B");

    JavaBeanSerializer serializer = new JavaBeanSerializer(B.class);
    serializer.write(new JSONSerializer(out), a, null, null, 0);

    Assert.assertEquals("{\"l0\":[\"A\",\"B\"],\"l1\":[]}", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JavaBeanSerializerTest.java

示例8: test_2_s

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_2_s() throws Exception {
    SerializeWriter out = new SerializeWriter();

    JavaBeanSerializer serializer = new JavaBeanSerializer(F.class);
    serializer.write(new JSONSerializer(out), new F(new E(123)), null, null, 0);

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

示例9: test_3_s

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_3_s() throws Exception {
    SerializeWriter out = new SerializeWriter();

    JavaBeanSerializer serializer = new JavaBeanSerializer(F.class);
    serializer.write(new JSONSerializer(out), new F(null), null, null, 0);

    Assert.assertEquals("{}", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JavaBeanSerializerTest.java

示例10: test_error_s

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_error_s() throws Exception {
    JSONException error = null;
    try {
        SerializeWriter out = new SerializeWriter();
        JavaBeanSerializer serializer = new JavaBeanSerializer(C.class);
        serializer.write(new JSONSerializer(out), new C(), null, null, 0);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:JavaBeanSerializerTest.java

示例11: test_error_1_s

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_error_1_s() throws Exception {
    JSONException error = null;
    try {
        SerializeWriter out = new SerializeWriter();
        JavaBeanSerializer serializer = new JavaBeanSerializer(D.class);
        serializer.write(new JSONSerializer(out), new D(), null, null, 0);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:JavaBeanSerializerTest.java

示例12: getPropertyValue

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
protected Object getPropertyValue(final Object currentObject, final String propertyName, boolean strictMode) {
    if (currentObject == null) {
        return null;
    }

    if (currentObject instanceof Map) {
        Map map = (Map) currentObject;
        return map.get(propertyName);
    }

    final Class<?> currentClass = currentObject.getClass();

    JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentClass);
    if (beanSerializer != null) {
        try {
            return beanSerializer.getFieldValue(currentObject, propertyName);
        } catch (Exception e) {
            throw new JSONPathException("jsonpath error, path " + path + ", segement " + propertyName, e);
        }
    }

    if (currentObject instanceof List) {
        List list = (List) currentObject;

        List<Object> fieldValues = new ArrayList<Object>(list.size());

        for (int i = 0; i < list.size(); ++i) {
            Object obj = list.get(i);
            Object itemValue = getPropertyValue(obj, propertyName, strictMode);
            fieldValues.add(itemValue);
        }

        return fieldValues;
    }
    throw new JSONPathException("jsonpath error, path " + path + ", segement " + propertyName);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:38,代码来源:JSONPath.java

示例13: evalSize

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
int evalSize(Object currentObject) {
    if (currentObject == null) {
        return -1;
    }

    if (currentObject instanceof Collection) {
        return ((Collection) currentObject).size();
    }

    if (currentObject instanceof Object[]) {
        return ((Object[]) currentObject).length;
    }

    if (currentObject.getClass().isArray()) {
        return Array.getLength(currentObject);
    }

    if (currentObject instanceof Map) {
        int count = 0;

        for (Object value : ((Map) currentObject).values()) {
            if (value != null) {
                count++;
            }
        }
        return count;
    }

    JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentObject.getClass());

    if (beanSerializer == null) {
        return -1;
    }

    try {
        return beanSerializer.getSize(currentObject);
    } catch (Exception e) {
        throw new JSONPathException("evalSize error : " + path, e);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:42,代码来源:JSONPath.java

示例14: test_0

import com.alibaba.fastjson.serializer.JavaBeanSerializer; //导入依赖的package包/类
public void test_0() throws Exception {
    new JavaBeanSerializer(A.class, Collections.<String, String> emptyMap());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:JavaBeanSerializerTest2.java


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