use of com.serotonin.json.util.TypeDefinition in project ma-core-public by infiniteautomation.
the class PopulateTest method test1.
static void test1() throws JsonException, IOException {
List<BaseClass> list = new ArrayList<BaseClass>();
list.add(new Subclass1());
list.add(new Subclass2());
String json = JsonWriter.writeToString(context, list);
System.out.println(json);
JsonReader reader = new JsonReader(context, json);
TypeDefinition type = new TypeDefinition(List.class, BaseClass.class);
list.clear();
reader.readInto(type, list);
System.out.println(list);
}
use of com.serotonin.json.util.TypeDefinition in project ma-core-public by infiniteautomation.
the class ReadTest method main.
public static void main(String[] args) throws Exception {
read("\"k\"", String.class);
read("{\"bigi\":1234567890123456,\"bigd\":1234567890123456.7890123456789,}", Object.class);
read("{\"bigi\":1234567890123456,\"bigd\":1234567890123456.7890123456789,}", new TypeDefinition(Map.class, String.class, BigDecimal.class));
read("{\"bigi\":1234567890123456,\"bigd\":1234567890123456.7890123456789,}", new TypeDefinition(HashMap.class, String.class, BigDecimal.class));
read("true", Boolean.TYPE);
read("true", Boolean.class);
read("10.1", Float.TYPE);
read("10.1", Float.class);
read("10.1", Double.TYPE);
read("10.1", Double.class);
read("1234567890123456789012345678901234567890", BigInteger.class);
read("1234567890123456789012345678901234567890", BigDecimal.class);
read("1234567890123456789012345678901234567890.1234567890123456789012345678901234567890", BigDecimal.class);
read("[\"qwer\",\"asdf\",\"zxcv\",]", new TypeDefinition(List.class, String.class));
read("[\"qwer\",\"asdf\",\"zxcv\",]", new TypeDefinition(ArrayList.class, String.class));
// read("{\"34\":\"34\",\"list\":[\"qwer\",\"asdf\",\"zxcv\"],\"34\":34}", new TypeDefinition(Map.class, null,
// String.class));
read("[\"qwer\",\"asdf\",\"zxcv\"]", String[].class);
read("\"SECOND\" \"SECOND\"", Enums.class);
read("{\"bigDecimal\":1.1,\"bigInteger\":2,\"boolean1\":false,\"byte1\":-4,\"double1\":5,\"float1\":6.1,\"int1\":7,\"long1\":-8,\"short1\":9,\"string1\":\"i'm a read string\"}", Primitives.class);
context.addSerializer(new PrimitiveSerializer(), Primitives.class);
read("{\"bigi\":1234567890123456,\"bigd\":1234567890123456.7890123456789,}", Primitives.class);
read("{\"myId\":\"Subclass2\",\"sub2Value\":\"sub2\",\"baseValue\":\"base\"}", Subclass2.class);
read("{\"value\":[\"qwer\",\"asdf\",\"zxcv\"]}", new TypeDefinition(GenObject.class, new TypeDefinition(List.class, String.class)));
read("[\"qwer\",\"asdf\",\"zxcv\"]", new ArrayList<String>(), new TypeDefinition(List.class, String.class));
read("{\"imSerializable\":{\"id\":12,\"value\":\"my value\"},\"list1\":null,\"list2\":null,\"map\":null,\"primitives\":{\"bigi\":1234567890123456,\"bigd\":1234567890123456.7890123456789},\"uuid\":\"ad9557f1-5e88-4b74-ab51-5b64364e6ccf\"}", Compound.class);
read("[[\"a1\",\"b1\",\"c1\"],[\"a2\",\"b2\",\"c2\"],[\"a3\",\"b3\",\"c3\"]]", new TypeDefinition(List.class, String[].class));
read("{\"rows\":[[\"a1\",\"b1\",\"c1\"],[\"a2\",\"b2\",\"c2\"],[\"a3\",\"b3\",\"c3\"]]}", ListArray.class);
read("{\"s1\":\"asdf\",\"s2\":\"zxcv\"}", new Mutable(), Mutable.class);
}
use of com.serotonin.json.util.TypeDefinition in project ma-core-public by infiniteautomation.
the class GenericTest method main.
public static void main(String[] args) throws Exception {
Class<?> varClass = GenObject.class;
Method method = varClass.getDeclaredMethod("getValue");
ParameterizedType paramType = new TypeDefinition(List.class, String.class);
ParameterizedType type = new TypeDefinition(varClass, paramType);
// System.out.println(TypeUtils.determineTypeArguments(varClass,
// (ParameterizedType) varClass.getGenericSuperclass()));
System.out.println(TypeUtils.resolveTypeVariable(type, method.getGenericReturnType()));
}
Aggregations