mirror of https://github.com/alibaba/fastjson2.git
support Stack
This commit is contained in:
parent
bfe2146b33
commit
a3bb9d24f6
|
|
@ -1941,6 +1941,7 @@ public class ObjectReaderBaseModule
|
|||
|| type == AbstractCollection.class
|
||||
|| type == AbstractList.class
|
||||
|| type == ArrayList.class
|
||||
|| type == Stack.class
|
||||
) {
|
||||
return ObjectReaderImplList.of(type, null, 0);
|
||||
// return new ObjectReaderImplList(type, (Class) type, ArrayList.class, Object.class, null);
|
||||
|
|
@ -2121,7 +2122,8 @@ public class ObjectReaderBaseModule
|
|||
|| rawType == List.class
|
||||
|| rawType == AbstractCollection.class
|
||||
|| rawType == AbstractList.class
|
||||
|| rawType == ArrayList.class) {
|
||||
|| rawType == ArrayList.class
|
||||
|| rawType == Stack.class) {
|
||||
if (itemClass == String.class) {
|
||||
return new ObjectReaderImplListStr((Class) rawType, ArrayList.class);
|
||||
} else if (itemClass == Long.class) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.alibaba.fastjson2.codec;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
public class StackTest {
|
||||
@Test
|
||||
public void test() {
|
||||
Stack<Node> nodestack = new Stack<>();
|
||||
Node node = new Node();
|
||||
node.setName("bb");
|
||||
nodestack.push(node);
|
||||
|
||||
String str = JSON.toJSONString(nodestack);
|
||||
|
||||
Stack result = JSON.parseObject(str, new com.alibaba.fastjson2.TypeReference<Stack<Node>>() {
|
||||
});
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Node
|
||||
extends HashMap<String, Object> {
|
||||
private String getName() {
|
||||
return this.get("name").toString();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.put("name", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue