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


Java ParserConfig.setAutoTypeSupport方法代码示例

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


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

示例1: test_autoTypeDeny

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_autoTypeDeny() throws Exception {
    ParserConfig config = new ParserConfig();
    assertFalse(config.isAutoTypeSupport());
    config.setAutoTypeSupport(true);
    assertTrue(config.isAutoTypeSupport());
    config.addDeny("com.alibaba.json.bvt.parser.deser.deny.DenyTest6");
    config.setAutoTypeSupport(false);

    Exception error = null;
    try {
        Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest6$Model\"}", Object.class, config);
        System.out.println(obj.getClass());
    } catch (JSONException ex) {
        error = ex;
    }
    assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:DenyTest6.java

示例2: test_autoTypeDeny

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_autoTypeDeny() throws Exception {
    ParserConfig config = new ParserConfig();

    assertFalse(config.isAutoTypeSupport());
    config.setAutoTypeSupport(true);
    assertTrue(config.isAutoTypeSupport());

    Properties properties = new Properties();
    properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");

    config.configFromPropety(properties);

    assertFalse(config.isAutoTypeSupport());

    Exception error = null;
    try {
        Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest7$Model\"}", Object.class, config);
        System.out.println(obj.getClass());
    } catch (JSONException ex) {
        error = ex;
    }
    assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:DenyTest7.java

示例3: test_autoTypeDeny

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_autoTypeDeny() throws Exception {
    ParserConfig config = new ParserConfig();

    assertFalse(config.isAutoTypeSupport());
    config.setAutoTypeSupport(true);
    assertTrue(config.isAutoTypeSupport());

    Properties properties = new Properties();
    properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
    properties.put(ParserConfig.AUTOTYPE_ACCEPT, "com.alibaba.json.bvt.parser.deser.deny.DenyTest9");
    // -ea -Dfastjson.parser.autoTypeAccept=com.alibaba.json.bvt.parser.deser.deny.DenyTest9
    config.configFromPropety(properties);

    assertFalse(config.isAutoTypeSupport());


    Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest9$Model\"}", Object.class, config);
    assertEquals(Model.class, obj.getClass());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:DenyTest9.java

示例4: test_for_issue

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
    ParserConfig config = new ParserConfig();
    config.setAutoTypeSupport(true);
    Map<Long, Bean> map = new HashMap<Long, Bean>();
    map.put(null, new Bean());
    Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);
    System.out.println(rmap);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Issue1503.java

示例5: test_codec_null

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_codec_null() throws Exception {
    V0 v = new V0();

    SerializeConfig mapping = new SerializeConfig();
    mapping.setAsmEnable(false);

    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    Assert.assertEquals("{\"value\":null}", text);

    ParserConfig config = new ParserConfig();
    config.setAutoTypeSupport(true);
    config.setAsmEnable(false);
    
    V0 v1 = JSON.parseObject(text, V0.class, config, JSON.DEFAULT_PARSER_FEATURE);

    Assert.assertEquals(v1.getValue(), v.getValue());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:ListFieldTest.java

示例6: test_for_issue

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
    ParserConfig parserConfig = new ParserConfig();
    parserConfig.setAutoTypeSupport(true);
    LinkedMultiValueMap<String, String> result = new LinkedMultiValueMap();
    result.add("test", "11111");
    String test = JSON.toJSONString(result, SerializerFeature.WriteClassName);
    JSON.parseObject(test, Object.class, parserConfig, JSON.DEFAULT_PARSER_FEATURE);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Issue1240.java

示例7: test_c3p0

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_c3p0() throws Exception {
    ParserConfig config = new ParserConfig();
    config.setAutoTypeSupport(true);

    Object obj = null;
    Exception error = null;
    try {
        obj = JSON.parseObject("{\"@type\":\"com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase\"}", Object.class, config);
        System.out.println(obj.getClass());
    } catch (JSONException ex) {
        error = ex;
    }
    assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:DenyTest5.java

示例8: test_autoTypeDeny

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_autoTypeDeny() throws Exception {
    ParserConfig config = new ParserConfig();

    assertFalse(config.isAutoTypeSupport());
    config.setAutoTypeSupport(true);
    assertTrue(config.isAutoTypeSupport());

    Properties properties = new Properties();
    properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
    config.configFromPropety(properties);

    assertFalse(config.isAutoTypeSupport());

    config.addAccept("com.alibaba.json.bvt.parser.deser.deny.DenyTest8");


    Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest8$Model\"}", Object.class, config);
    assertEquals(Model.class, obj.getClass());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:DenyTest8.java

示例9: test_0

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_0() throws Exception {
    ParserConfig config = new ParserConfig();
    config.setAutoTypeSupport(true);

    System.out.println(Model.class.isAnnotationPresent(JSONField.class));
    String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest1$Model\",\"id\":123}";

    Model model2 = (Model) JSON.parseObject(text, Object.class, config);
    assertEquals(123, model2.id);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:AutoTypeTest1.java

示例10: test_for_issue

import com.alibaba.fastjson.parser.ParserConfig; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
    ParserConfig config = new ParserConfig();
    config.setAutoTypeSupport(true);
    String text = "{\"id\": \"439a3213-e734-4bf3-9870-2c471f43d651\", \"instance\": \"v1\", \"interface\": \"com.xxx.aplan.UICommands\", \"method\": \"start\", \"params\": [\"tony\"], \"@type\": \"com.alibaba.json.bvt.issue_1500.Issue1558$Request\"}";

    JSON.parseObject(text, Request.class, config);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:Issue1558.java


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