Skip to content

Commit

Permalink
fix final field initialized in the constructor set twice for issue al…
Browse files Browse the repository at this point in the history
  • Loading branch information
yanxutao89 authored and wenshao committed Sep 18, 2023
1 parent de09ea2 commit 0796a9b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public void accept(T object, Object value) {
throw new JSONException("set " + fieldName + " error", e);
}

if (collection == Collections.EMPTY_LIST || collection == Collections.EMPTY_SET || collection == null) {
if (collection == Collections.EMPTY_LIST
|| collection == Collections.EMPTY_SET
|| collection == null
|| collection.equals(value)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.alibaba.fastjson2.issues_1800;

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue1873 {
@Test
public void test() {
String json = "[{\"array\":[\"test1\",\"test2\",\"test3\"]}]";
List<ListTest> values = JSONObject.parseObject(json, TypeReference.collectionType(List.class, ListTest.class));
assertEquals(json, JSONObject.toJSONString(values));
json = "{\"array\":[\"test1\",\"test2\",\"test3\"]}";
ListTest listTest = JSONObject.parseObject(json, ListTest.class);
assertEquals(json, JSONObject.toJSONString(listTest));
}

static class ListTest {
public final List<String> array;

public ListTest(List<String> array) {
this.array = array;
}
}
}

0 comments on commit 0796a9b

Please sign in to comment.