當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。