Skip to content

Commit

Permalink
bug fix for reference detection #304
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 22, 2022
1 parent d6ecd1e commit bd185db
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions core/src/test/java/com/alibaba/fastjson2/issues/Issue304.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ public void write() {
assertEquals("[{\"item\":{\"name\":\"testtt\"},\"name\":\"test\"},{\"item\":{\"$ref\":\"$[0].item\"},\"name\":\"test\"},{\"item\":{\"$ref\":\"$[0].item\"},\"name\":\"test\"},{\"item\":{\"$ref\":\"$[0].item\"},\"name\":\"test\"}]", result);
}

public void testRead0() {
public void testRead() {
List<Bean> list2 = JSON.parseArray(result, Bean.class);
assertSame(list2.get(0).item, list2.get(1).item);
}

@Test
public void readDefault() {
public void readPrivate() {
List<Bean1> list3 = JSON.parseArray(result, Bean1.class);
assertSame(list3.get(0).item, list3.get(1).item);
}

@Test
public void readUTF8() {
List<Bean> list3 = JSON.parseArray(result.getBytes(StandardCharsets.UTF_8), Bean.class);
assertSame(list3.get(0).item, list3.get(1).item);
}
Expand Down Expand Up @@ -128,4 +134,25 @@ public void setItem(Bean item) {
this.item = item;
}
}

public static class Bean1 {
private String name;
private Bean1 item;

public String getName() {
return name;
}

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

public Bean1 getItem() {
return item;
}

public void setItem(Bean1 item) {
this.item = item;
}
}
}

0 comments on commit bd185db

Please sign in to comment.