package com.alibaba.json.bvt.parser;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONCreator;
import com.alibaba.fastjson.annotation.JSONField;

import junit.framework.TestCase;

public class JSONCreatorTest3 extends TestCase {

    public void test_create_1() throws Exception {
        Entity vo = JSON.parseObject("{\"id\":1001,\"name\":\"wenshao\",\"obj\":{\"$ref\":\"$\"}}", Entity.class);
        Assert.assertEquals(1001, vo.getId());
        Assert.assertEquals("wenshao", vo.getName());
        Assert.assertSame(vo, vo.getObj());
    }

    public static class Entity {

        private final int    id;
        private final String name;
        private final Entity obj;

        @JSONCreator
        public Entity(@JSONField(name = "id") int id, @JSONField(name = "name") String name,
                      @JSONField(name = "obj") Entity obj){
            this.id = id;
            this.name = name;
            this.obj = obj;
        }

        public int getId() {
            return id;
        }

        public String getName() {
            return name;
        }

        public Entity getObj() {
            return obj;
        }

    }

}

@@ -91,16 +91,59 @@
 n.JSON;%0A
+import com.alibaba.fastjson.JSONException;%0A
 import c
@@ -633,24 +633,692 @@
 bj());%0A    %7D
+%0A    %0A    public void test_create_error() throws Exception %7B%0A        Exception error = null;%0A        try %7B%0A            JSON.parseObject(%22%7B%5C%22id%5C%22:1001,%5C%22name%5C%22:%5C%22wenshao%5C%22,%5C%22obj%5C%22:%7B%5C%22$ref%5C%22:123%7D%7D%22, Entity.class);%0A        %7D catch (JSONException ex) %7B%0A            error = ex;%0A        %7D%0A        Assert.assertNotNull(error);%0A    %7D%0A    %0A    public void test_create_error_2() throws Exception %7B%0A        Exception error = null;%0A        try %7B%0A            JSON.parseObject(%22%7B%5C%22id%5C%22:1001,%5C%22name%5C%22:%5C%22wenshao%5C%22,%5C%22obj%5C%22:%7B%5C%22$ref%5C%22:%5C%22$%5C%22,%5C%22value%5C%22:123%7D%7D%22, Entity.class);%0A        %7D catch (JSONException ex) %7B%0A            error = ex;%0A        %7D%0A        Assert.assertNotNull(error);%0A    %7D
 %0A%0A    public

add testcase