Skip to content

Commit

Permalink
fix Set deserialize error, for issue #1417
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 13, 2023
1 parent 08f3fa6 commit 76415d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,13 @@ public Map<String, Object> readObject() {
} else {
throw new JSONException(info("illegal input " + ch));
}
case 'S':
if (nextIfSet()) {
val = read(Set.class);
break;
} else {
throw new JSONException(info("illegal input " + ch));
}
default:
throw new JSONException(info("illegal input " + ch));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.alibaba.fastjson2.issues_1000;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
import org.junit.jupiter.api.Test;

import java.util.Map;
import java.util.Set;

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

public class Issue1417 {
@Test
public void test() {
String str = "{\"value\":Set[1]}";
JSONReader jsonReader = JSONReader.of(str);
Map<String, Object> object = jsonReader.readObject();
Set value = (Set) object.get("value");
assertEquals("[1]", JSON.toJSONString(value));
}
}

0 comments on commit 76415d5

Please sign in to comment.