Search in sources :

Example 1 with TypeReference

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

the class DefaultExtJSONParser_parseArray_2 method test_error_1.

public void test_error_1() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[['1']]");
    parser.config(Feature.AllowISO8601DateFormat, false);
    Exception error = null;
    try {
        parser.parseArrayWithType(new TypeReference<Map<?, ?>>() {
        }.getType());
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) TypeReference(com.alibaba.fastjson.TypeReference)

Example 2 with TypeReference

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

the class DefaultExtJSONParser_parseArray method test_16.

public void test_16() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[[1]]");
    parser.config(Feature.AllowISO8601DateFormat, false);
    Object[] array = parser.parseArray(new Type[] { new TypeReference<List<Integer>>() {
    }.getType() });
    Assert.assertEquals(new Integer(1), ((List<Integer>) (array[0])).get(0));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) TypeReference(com.alibaba.fastjson.TypeReference)

Example 3 with TypeReference

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

the class JSONReader_typeRef method test_array_1.

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

Example 4 with TypeReference

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

the class AutoKeeperClusterServiceImpl method doToModel.

private AutoKeeperCluster doToModel(AutoKeeperClusterDO autoKeeperClusterDo) {
    AutoKeeperCluster autoKeeperCluster = new AutoKeeperCluster();
    autoKeeperCluster.setId(autoKeeperClusterDo.getId());
    autoKeeperCluster.setClusterName(autoKeeperClusterDo.getClusterName());
    autoKeeperCluster.setDescription(autoKeeperClusterDo.getDescription());
    autoKeeperCluster.setServerList(JsonUtils.unmarshalFromString(autoKeeperClusterDo.getServerList(), new TypeReference<List<String>>() {
    }));
    autoKeeperCluster.setGmtCreate(autoKeeperClusterDo.getGmtCreate());
    autoKeeperCluster.setGmtModified(autoKeeperClusterDo.getGmtModified());
    return autoKeeperCluster;
}
Also used : AutoKeeperCluster(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster) TypeReference(com.alibaba.fastjson.TypeReference)

Example 5 with TypeReference

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

the class DataColumnPairGroupServiceImpl method doToModel.

/*-------------------------------------------------------------*/
/**
     * 用于DO对象转化为Model对象
     */
private ColumnGroup doToModel(DataColumnPairGroupDO dataColumnPairGroupDo) {
    ColumnGroup columnGroup = new ColumnGroup();
    columnGroup.setId(dataColumnPairGroupDo.getId());
    List<ColumnPair> columnPairs = new ArrayList<ColumnPair>();
    if (StringUtils.isNotBlank(dataColumnPairGroupDo.getColumnPairContent())) {
        columnPairs = JsonUtils.unmarshalFromString(dataColumnPairGroupDo.getColumnPairContent(), new TypeReference<ArrayList<ColumnPair>>() {
        });
    }
    columnGroup.setColumnPairs(columnPairs);
    columnGroup.setDataMediaPairId(dataColumnPairGroupDo.getDataMediaPairId());
    columnGroup.setGmtCreate(dataColumnPairGroupDo.getGmtCreate());
    columnGroup.setGmtModified(dataColumnPairGroupDo.getGmtModified());
    return columnGroup;
}
Also used : ColumnPair(com.alibaba.otter.shared.common.model.config.data.ColumnPair) ArrayList(java.util.ArrayList) TypeReference(com.alibaba.fastjson.TypeReference) ColumnGroup(com.alibaba.otter.shared.common.model.config.data.ColumnGroup)

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