package com.alibaba.fastjson.deserializer;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;

import org.junit.Assert;
import org.junit.Test;


/**
 * Created by jiangyu on 2017-03-03 11:33.
 */
public class IgnoreTypeDeserializer {
    @Test(expected = JSONException.class)
    public void parseObjectWithNotExistTypeThrowException() {
        String s = "{\"@type\":\"com.alibaba.fastjson.ValueBean\",\"val\":1}";
        JSONObject.parseObject(s, ValueBean.class);
    }

    @Test
    public void parseObjectWithNotExistType() {
        String s = "{\"@type\":\"com.alibaba.fastjson.ValueBean\",\"val\":1}";
        ValueBean v = JSONObject.parseObject(s, ValueBean.class, Feature.IgnoreAutoType);
        Assert.assertNotNull(v);
        Assert.assertEquals(new Integer(1), v.getVal());
    }

    @Test
    public void parseWithNotExistType() {
        String s = "{\"@type\":\"com.alibaba.fastjson.ValueBean\",\"val\":1}";
        Object object = JSONObject.parse(s);
        Assert.assertNotNull(object);
        Assert.assertTrue(object instanceof JSONObject);
        Assert.assertEquals(new Integer(1), JSONObject.class.cast(object).getInteger("val"));
    }

    @Test
    public void parseWithExistType() {
        String s = "{\"@type\":\"com.alibaba.fastjson.deserializer.ValueBean\",\"val\":1}";
        Object object = JSONObject.parse(s);
        Assert.assertNotNull(object);
        Assert.assertTrue(object instanceof ValueBean);
        Assert.assertEquals(new Integer(1), ValueBean.class.cast(object).getVal());
    }

    @Test
    public void parseObjectWithExistType() {
        String s = "{\"@type\":\"com.alibaba.fastjson.deserializer.ValueBean\",\"val\":1}";
        ValueBean object = JSONObject.parseObject(s, ValueBean.class);
        Assert.assertNotNull(object);
        Assert.assertEquals(new Integer(1), object.getVal());
    }

}

@@ -165,16 +165,89 @@
 ature;%0A%0A
+import com.alibaba.fastjson.parser.ParserConfig;%0Aimport org.junit.After;%0A
 import o
@@ -263,16 +263,41 @@
 Assert;%0A
+import org.junit.Before;%0A
 import o
@@ -402,16 +402,220 @@
 lizer %7B%0A
+    %0A    @Before%0A    public void before() %7B%0A        ParserConfig.global.setAutoTypeSupport(true);%0A    %7D%0A%0A    @After%0A    public void after() %7B%0A        ParserConfig.global.setAutoTypeSupport(false);%0A    %7D%0A%0A
     @Tes

fix 2823