package com.alibaba.json.bvt.ref;

import junit.framework.Assert;
import junit.framework.TestCase;

import com.alibaba.fastjson.JSON;

public class TestRef6 extends TestCase {

    public void test_0() throws Exception {
        Family family = new Family();

        Person pA = new Person("a");

        Person pB = new Person("b");

        family.setMembers(new Person[] { pA, pB });
        family.setMaster(pA);

        Family[] familyArray = new Family[] { family };
        String text = JSON.toJSONString(familyArray);
        System.out.println(text);

        Family[] result = JSON.parseObject(text, Family[].class);

        Assert.assertSame(result[0].getMaster(), result[0].getMembers()[0]);

    }

    public static class Family {

        private Person   master;
        private Person[] members;

        public Person getMaster() {
            return master;
        }

        public void setMaster(Person master) {
            this.master = master;
        }

        public Person[] getMembers() {
            return members;
        }

        public void setMembers(Person[] members) {
            this.members = members;
        }

    }

    public static class Person {

        private String name;

        public Person(){

        }

        public Person(String name){
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }
}

@@ -217,46 +217,8 @@
 on %7B
-%0A        Family family = new Family();
 %0A%0A  
@@ -248,25 +248,24 @@
 erson(%22a%22);%0A
-%0A
         Pers
@@ -294,30 +294,60 @@
 );%0A%0A        
-family
+Family fA = new Family();%0A        fA
 .setMembers(
@@ -381,21 +381,209 @@
        f
-amily
+A.setMaster(pA);%0A%0A        Person pC = new Person(%22c%22);%0A        Person pD = new Person(%22d%22);%0A        %0A        Family fB = new Family();%0A        fB.setMembers(new Person%5B%5D %7B pC, pD %7D);%0A        fB
 .setMast
@@ -578,33 +578,33 @@
   fB.setMaster(p
-A
+C
 );%0A%0A        Fami
@@ -638,21 +638,21 @@
 ly%5B%5D %7B f
-amily
+A, fB
  %7D;%0A    
@@ -879,16 +879,93 @@
 s()%5B0%5D);
+%0A        Assert.assertSame(result%5B1%5D.getMaster(), result%5B1%5D.getMembers()%5B0%5D);
 %0A%0A    %7D%0A

add test