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


Java JSONSerializer.config方法代码示例

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


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

示例1: toJSONString

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public static final String toJSONString(Object object) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.config(SerializerFeature.SortField, false);
        serializer.config(SerializerFeature.UseSingleQuotes, true);

        serializer.write(object);

        return out.toString();
    } catch (StackOverflowError e) {
        throw new JSONException("maybe circular references", e);
    } finally {
        out.close();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:MapTest.java

示例2: toJSONBytes

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public static final byte[] toJSONBytes(Object object, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
            serializer.config(feature, true);
        }

        serializer.write(object);

        return out.toBytes("UTF-8");
    } finally {
        out.close();
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:17,代码来源:JSON.java

示例3: test_9_s

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_9_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer();

    serializer.config(SerializerFeature.QuoteFieldNames, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    serializer.config(SerializerFeature.WriteMapNullValue, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.WriteMapNullValue));

    SerializeWriter out = new SerializeWriter();

    Map map = new LinkedHashMap();
    map.put("a", null);
    map.put("age", 33);
    map.put("c", null);

    serializer.write(map);

    Assert.assertEquals("{age:33}", serializer.getWriter().toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:JSONSerializerFeatureTest.java

示例4: toJSONString

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
            serializer.config(feature, true);
        }

        serializer.config(SerializerFeature.WriteDateUseDateFormat, true);

        setFilter(serializer, filter);

        serializer.write(object);

        return out.toString();
    } finally {
        out.close();
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:21,代码来源:JSON.java

示例5: test_0

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_0() throws Exception {
    JSONSerializer serializer = new JSONSerializer();

    int size = JSONSerializerMapTest.size(serializer.getMapping());
    serializer.config(SerializerFeature.WriteEnumUsingToString, false);
    serializer.config(SerializerFeature.WriteEnumUsingName, false);
    serializer.write(Type.A);

    Assert.assertTrue(size < JSONSerializerMapTest.size(serializer.getMapping()));

    Assert.assertEquals(Integer.toString(Type.A.ordinal()), serializer.getWriter().toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JSONSerializerTest2.java

示例6: test_3

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_3() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.write(new A(Type.B));

    Assert.assertEquals("{\"type\":\"B\"}", serializer.getWriter().toString());

    A a = JSON.parseObject(serializer.getWriter().toString(), A.class);
    Assert.assertEquals(a.getType(), Type.B);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:JSONSerializerTest2.java

示例7: test_3

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_3() throws Exception {
	SerializeWriter out = new SerializeWriter();
	JSONSerializer serializer = new JSONSerializer(out);
	serializer.config(SerializerFeature.UseSingleQuotes, true);

	serializer.write(new TestEntity("张三"));
	Assert.assertEquals("{'value':'张三'}", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:StringSerializerTest.java

示例8: test_2

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

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294552193000L));

    Assert.assertEquals("\"2011-01-09T13:49:53+08:00\"", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:DateTest.java

示例9: test_4

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

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294502400000L));

    Assert.assertEquals("'2011-01-09+08:00'", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:DateTest.java

示例10: toJSONString

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public static final String toJSONString(Object object, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (SerializerFeature feature : features) {
            serializer.config(feature, true);
        }
        serializer.write(object);
        String serializeWriter = out.toString();
        return serializeWriter;
    } finally {
        out.close();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:JSON.java

示例11: writeObject

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void writeObject(Object obj) throws IOException {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.write(obj);
    out.writeTo(writer);
    writer.println();
    writer.flush();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:10,代码来源:FastJsonObjectOutput.java

示例12: test_7

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

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294506000000L));

    Assert.assertEquals("\"2011-01-09T01:00:00+08:00\"", out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:DateTest.java

示例13: test_6

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_6() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());

    serializer.config(SerializerFeature.QuoteFieldNames, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));

    serializer.write(Collections.singletonMap("a'ge", 33));

    Assert.assertEquals("{'a\\'ge':33}", serializer.getWriter().toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JSONSerializerFeatureTest.java

示例14: test_date_3

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_date_3() throws Exception {
    SerializeWriter out = new SerializeWriter();
    SerializeConfig config = new SerializeConfig();
    JSONSerializer serializer = new JSONSerializer(out, config);

    serializer.config(SerializerFeature.WriteClassName, true);
    serializer.write(new VO());

    Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.serializer.DateFormatSerializerTest$VO\"}",
                        out.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:DateFormatSerializerTest.java

示例15: serialize

import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
@Override
public byte[] serialize(Object data) throws IOException {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.config(SerializerFeature.WriteClassName, true);
    serializer.write(data);
    return out.toBytes(null);
}
 
开发者ID:chenxh,项目名称:rpc,代码行数:10,代码来源:FastJsonSerialization.java


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