-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix read only field deserialize error, for issue #2532
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
core/src/test/java/com/alibaba/fastjson2/issues_2500/Issue2532.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.alibaba.fastjson2.issues_2500; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2532 { | ||
String jsonString = "{\"collectionField\": [1, 2, 3]}"; | ||
|
||
class ImmutableCollectionExample { | ||
private final Collection<Integer> collectionField; | ||
|
||
public ImmutableCollectionExample(Collection<Integer> collectionField) { | ||
this.collectionField = Collections.unmodifiableCollection(new ArrayList<>(collectionField)); | ||
} | ||
|
||
public Collection<Integer> getCollectionField() { | ||
return collectionField; | ||
} | ||
} | ||
|
||
@Test | ||
public void testParseObjectWithImmutableCollectionField() throws Exception { | ||
ImmutableCollectionExample result = JSON.parseObject(jsonString, ImmutableCollectionExample.class); | ||
assertEquals(Arrays.asList(1, 2, 3), new ArrayList<>(result.getCollectionField())); | ||
} | ||
} |