Search in sources :

Example 6 with TypeReference

use of com.alibaba.fastjson.TypeReference in project fastjson by alibaba.

the class TypeUtilsTest_cast method test_cast_1.

public void test_cast_1() throws Exception {
    ParameterizedType parameterizedType = (ParameterizedType) new TypeReference<List<?>>() {
    }.getType();
    Type type = parameterizedType.getActualTypeArguments()[0];
    Assert.assertEquals(null, TypeUtils.cast("", type, null));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TypeReference(com.alibaba.fastjson.TypeReference)

Example 7 with TypeReference

use of com.alibaba.fastjson.TypeReference in project fastjson by alibaba.

the class DefaultObjectDeserializerTest2 method test_1.

public void test_1() throws Exception {
    String input = "{'map':{}}";
    DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
    SortedMap<String, SortedMap> map = JSON.parseObject(input, new TypeReference<SortedMap<String, SortedMap>>() {
    }.getType());
    Assert.assertEquals(TreeMap.class, map.get("map").getClass());
}
Also used : SortedMap(java.util.SortedMap) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) TypeReference(com.alibaba.fastjson.TypeReference)

Example 8 with TypeReference

use of com.alibaba.fastjson.TypeReference in project fastjson by alibaba.

the class ArrayListStringDeserializerTest method test_string_error_not_eof.

public void test_string_error_not_eof() throws Exception {
    JSONException ex = null;
    try {
        JSON.parseObject("[}", new TypeReference<List<String>>() {
        }.getType(), 0, Feature.AllowSingleQuotes);
    } catch (JSONException e) {
        ex = e;
    }
    Assert.assertNotNull(ex);
}
Also used : JSONException(com.alibaba.fastjson.JSONException) TypeReference(com.alibaba.fastjson.TypeReference)

Example 9 with TypeReference

use of com.alibaba.fastjson.TypeReference in project fastjson by alibaba.

the class JSONReader_typeRef method test_array.

public void test_array() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("[{\"id\":123}]"));
    List<VO> list = reader.readObject(new TypeReference<List<VO>>() {
    }.getType());
    Assert.assertEquals(123, list.get(0).getId());
    reader.close();
}
Also used : StringReader(java.io.StringReader) TypeReference(com.alibaba.fastjson.TypeReference) JSONReader(com.alibaba.fastjson.JSONReader)

Example 10 with TypeReference

use of com.alibaba.fastjson.TypeReference in project atlas by alibaba.

the class BundleInfoUtils method getBundleInfoMap.

private static Map<String, BundleInfo> getBundleInfoMap(AppVariantContext appVariantContext) throws IOException {
    File baseBunfleInfoFile = new File(appVariantContext.getScope().getGlobalScope().getProject().getProjectDir(), "bundleBaseInfoFile.json");
    Map<String, BundleInfo> bundleFileMap = Maps.newHashMap();
    if (null != baseBunfleInfoFile && baseBunfleInfoFile.exists() && baseBunfleInfoFile.canRead()) {
        String bundleBaseInfo = FileUtils.readFileToString(baseBunfleInfoFile, "utf-8");
        bundleFileMap = JSON.parseObject(bundleBaseInfo, new TypeReference<Map<String, BundleInfo>>() {
        });
    }
    return bundleFileMap;
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) TypeReference(com.alibaba.fastjson.TypeReference) File(java.io.File)

Aggregations

TypeReference (com.alibaba.fastjson.TypeReference)11 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)3 JSONReader (com.alibaba.fastjson.JSONReader)2 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)2 File (java.io.File)2 StringReader (java.io.StringReader)2 JSONException (com.alibaba.fastjson.JSONException)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AutoKeeperCluster (com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster)1 ColumnGroup (com.alibaba.otter.shared.common.model.config.data.ColumnGroup)1 ColumnPair (com.alibaba.otter.shared.common.model.config.data.ColumnPair)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1 Node (org.dom4j.Node)1