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


Java JSON.DEFAULT_GENERATE_FEATURE属性代码示例

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


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

示例1: SerializeWriter

public SerializeWriter(Writer writer) {
    this.writer = writer;
    this.features = JSON.DEFAULT_GENERATE_FEATURE;
    SoftReference<char[]> ref = (SoftReference) bufLocal.get();
    if (ref != null) {
        this.buf = (char[]) ref.get();
        bufLocal.set(null);
    }
    if (this.buf == null) {
        this.buf = new char[1024];
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:SerializeWriter.java

示例2: test_enum_ordinal

public void test_enum_ordinal() throws Exception {
    Model model = new Model();
    model.type = Type.Big;

    int serializerFeatures = JSON.DEFAULT_GENERATE_FEATURE & ~SerializerFeature.WriteEnumUsingName.mask;
    String text = JSON.toJSONString(model, serializerFeatures);
    System.out.println(text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:EnumOrdinalTest.java

示例3: test_for_issue

public void test_for_issue() throws Exception {
    SerializeWriter writer = new SerializeWriter(null, JSON.DEFAULT_GENERATE_FEATURE, new SerializerFeature[0]);
    int defaultBufferSize = writer.getBufferLength();
    String encoded = JSON.toJSONString(new FooBar(defaultBufferSize));
    JSONObject decoded = (JSONObject) JSON.parse(encoded);
    JSONArray dataToEncode = decoded.getJSONArray("dataToEncode"); 
    Assert.assertEquals(5, dataToEncode.size());
    writer.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Issue771.java

示例4: test_writeSlashAsSpecial

public void test_writeSlashAsSpecial() throws Exception {
    int features = JSON.DEFAULT_GENERATE_FEATURE;
    features = SerializerFeature.config(features, SerializerFeature.WriteSlashAsSpecial, true);
    features = SerializerFeature.config(features, SerializerFeature.WriteTabAsSpecial, true);
    features = SerializerFeature.config(features, SerializerFeature.DisableCircularReferenceDetect, true);
    features = SerializerFeature.config(features, SerializerFeature.SortField, false);

    Assert.assertEquals("\"\\/\"", JSON.toJSONString("/", features));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:TestWriteSlashAsSpecial.java

示例5: SerializeWriter

public SerializeWriter(Writer writer){
    this.writer = writer;
    this.features = JSON.DEFAULT_GENERATE_FEATURE;

    SoftReference<char[]> ref = bufLocal.get();

    if (ref != null) {
        buf = ref.get();
        bufLocal.set(null);
    }

    if (buf == null) {
        buf = new char[1024];
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:15,代码来源:SerializeWriter.java

示例6: SerializeWriter

public SerializeWriter(Writer writer){
    this(writer, JSON.DEFAULT_GENERATE_FEATURE, SerializerFeature.EMPTY);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:3,代码来源:SerializeWriter.java

示例7: serializeToJSON

/**
 * 将对象序列化为 JSON 字符串;
 *
 * @param data           要序列化的对象;
 * @param serializedType 要序列化的对象的输出的类型;<br>
 *                       指定该对象的父类或者某一个实现的接口类型,序列化输出的 JSON 将只包含该类型的属性;<br>
 *                       如果指定为 null, 则按对象本身的类型进行序列化;
 * @param dateFormat     日期格式;
 * @param prettyFormat   是否以包含换行和缩进的良好格式输出 JSON;
 * @return
 */
public static String serializeToJSON(Object data, Class<?> serializedType, String dateFormat,
                                     boolean prettyFormat){
    SerializeWriter out;

    if (prettyFormat) {
        out = new SerializeWriter((Writer) null, JSON.DEFAULT_GENERATE_FEATURE, SerializerFeature.PrettyFormat);
    } else {
        out = new SerializeWriter((Writer) null, JSON.DEFAULT_GENERATE_FEATURE, SerializerFeature.EMPTY);
    }

    try {
        if (data == null) {
            return null;
            //				out.writeNull();
        } else {
            // 确定要序列化的类型;
            if (serializedType == null) {
                serializedType = data.getClass();
            } else if ((!PrimitiveUtils.isPrimitiveType(serializedType))
                    && (!PrimitiveUtils.isPrimitiveType(data.getClass()))
                    && (!serializedType.isAssignableFrom(data.getClass()))) {
                throw new IllegalArgumentException("The serialized type[" + serializedType.getName()
                        + "] isn't assignable from the data type[" + data.getClass().getName() + "]!");
            }

            if (PrimitiveUtils.isWrapping(data.getClass(), serializedType)) {
                //避免 serializedType 原生的值类型时引发 fastjson 的序列化异常;
                serializedType = data.getClass();
            }

            JSONSerializer serializer = new JSONSerializer(out, SerializeConfig.globalInstance);

            // 配置日期格式;
            if (dateFormat != null && dateFormat.length() != 0) {
                serializer.setDateFormat(dateFormat);
                serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
            }

            // 序列化;
            ObjectSerializer writer = serializer.getObjectWriter(serializedType);

            writer.write(serializer, data, null, null, JSON.DEFAULT_GENERATE_FEATURE);
        }
        return out.toString();
    } catch (IOException e) {
        throw new IllegalStateException(
                "Error occurred on serializing type[" + serializedType.getName() + "]! --" + e.getMessage(), e);
    } finally {
        out.close();
    }
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:62,代码来源:SerializeUtils.java


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