fix Set deserialize error, for issue #1417

This commit is contained in:
shaojin.wensj 2023-05-14 06:08:17 +08:00
parent 08f3fa62f3
commit 76415d5149
2 changed files with 28 additions and 0 deletions

View File

@ -1927,6 +1927,13 @@ public abstract class JSONReader
} 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));
}

View File

@ -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));
}
}