当前位置: 首页>>代码示例>>Java>>正文


Java TypeReference类代码示例

本文整理汇总了Java中com.alibaba.fastjson.TypeReference的典型用法代码示例。如果您正苦于以下问题:Java TypeReference类的具体用法?Java TypeReference怎么用?Java TypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TypeReference类属于com.alibaba.fastjson包,在下文中一共展示了TypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initRecord

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
private void initRecord(Context context) {
    this.mPreferences = context.getSharedPreferences(DOWNLOAD_RECORD, 0);
    this.recordMap = (Map) FastJsonUtils.fromJson(this.mPreferences.getString(CacheKey
            .DOWNLOAD_RECORD, null), new TypeReference<Map<String, DownloadRecord>>() {
    });
    if (this.recordMap == null) {
        String oldRecord = FileCache.get(context, DOWNLOAD_RECORD).getAsString(CacheKey
                .DOWNLOAD_RECORD);
        this.recordMap = (Map) FastJsonUtils.fromJson(oldRecord, new
                TypeReference<Map<String, DownloadRecord>>() {
        });
        if (this.recordMap == null) {
            this.recordMap = new HashMap();
            return;
        }
        Editor editor = this.mPreferences.edit();
        editor.putString(CacheKey.DOWNLOAD_RECORD, oldRecord);
        editor.apply();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:DownloadHelper.java

示例2: validateElvesMqMessage

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
/**
 * @Title: validateElvesMqMessage
 * @Description: 校验接收到的mq消息body 内容, 是否符合elves模块通讯的规范
 * @param msgStr
 * @return boolean    返回类型
 */
public static boolean validateElvesMqMessage(String msgStr){
    try {
        Map<String,Object> reqMsgMap =JSON.parseObject(msgStr,new TypeReference<Map<String, Object>>(){});
        if(null==reqMsgMap||null==reqMsgMap.get("mqkey")||null==reqMsgMap.get("mqtype")){
            return false;
        }
        String[] arr = reqMsgMap.get("mqkey").toString().trim().split("[.]");
        if(null==arr||arr.length!=3){
            return false;
        }

        String mqtype = reqMsgMap.get("mqtype").toString().trim();
        if(!"call".equals(mqtype)&&!"cast".equals(mqtype)){
            return false;
        }

        if(null!=reqMsgMap.get("mqbody")){
            JSON.parseObject(reqMsgMap.get("mqbody").toString().trim(),new TypeReference<Map<String, Object>>(){});
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:elves-project,项目名称:scheduler,代码行数:31,代码来源:ElvesMqMessage.java

示例3: get

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
@Override
public <T> T get(final String bizkey, final String nameSpace, TypeReference<T> type,
		final GetDataCallBack<T> gbs) {
   	final String key = CacheUtils.getKeyByNamespace(bizkey,nameSpace);
   	String res = get(bizkey,nameSpace,null);
   	T rtn = null;
   	if(StringUtils.isNotEmpty(res)){
   		rtn = CacheUtils.parseObject(key,res, type);
   	}else{
   		if(gbs!=null){
   			rtn = gbs.invoke();
   			//取出的数据要set回去
   			if(null!=rtn){
   				set(bizkey,nameSpace,rtn,gbs.getExpiredTime());
   			}
   		}
   	}
   	return rtn;
}
 
开发者ID:ningyu1,项目名称:jodis-client,代码行数:20,代码来源:RedisClientImpl.java

示例4: test_list

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
public void test_list() throws Exception {
    List<Model> list = new ArrayList<Model>();
    for (int i = 0; i < 1000; ++i) {
        Model model = new Model();
        model.f0 = random(64);
        model.f1 = random(64);
        model.f2 = random(64);
        model.f3 = random(64);
        model.f4 = random(64);
        list.add(model);
    }
    String text = JSON.toJSONString(list);
    List<Model> list2 = JSON.parseObject(text, new TypeReference<List<Model>>() {});
    Assert.assertEquals(list.size(), list2.size());
    for (int i = 0; i < 1000; ++i) {
        Assert.assertEquals(list.get(i).f0, list2.get(i).f0);    
        Assert.assertEquals(list.get(i).f1, list2.get(i).f1);    
        Assert.assertEquals(list.get(i).f2, list2.get(i).f2);    
        Assert.assertEquals(list.get(i).f3, list2.get(i).f3);    
        Assert.assertEquals(list.get(i).f4, list2.get(i).f4);    
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:BigStringFieldTest.java

示例5: generateKeepFile

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
@NotNull
private static File generateKeepFile(List<AwbBundle> awbBundles, File dir) throws IOException {

    KeepConverter refClazzContainer = new KeepConverter();
    for (AwbBundle awbBundle : awbBundles) {
        if (null != awbBundle.getKeepProguardFile() && awbBundle.getKeepProguardFile().exists()) {

            String json = FileUtils.readFileToString(awbBundle.getKeepProguardFile());
            Map<String, ClazzRefInfo> refClazzMap = JSON.parseObject(json,
                                                                     new TypeReference<Map<String, ClazzRefInfo>>
                                                                         () {});

            refClazzContainer.addRefClazz(refClazzMap);

        } else {
            sLogger.error(
                "missing " + awbBundle.getKeepProguardFile().getAbsolutePath());
        }
    }

    File maindexkeep = new File(dir, "maindexkeep.cfg");
    FileUtils.writeLines(maindexkeep, refClazzContainer.convertToKeeplines());
    return maindexkeep;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:25,代码来源:AtlasProguardHelper.java

示例6: test_issue

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
public void test_issue() throws Exception {
    Map<String, List<String>> totalMap = new HashMap<String, List<String>>();
    for (int i = 0; i < 10; i++) {
        List<String> list = new ArrayList<String>();
        for (int j = 0; j < 2; j++) {
            list.add("list" + j);
        }
        totalMap.put("map" + i, list);
    }
    List<Map.Entry<String, List<String>>> mapList = new ArrayList<Map.Entry<String, List<String>>>(totalMap.entrySet());
    String jsonString = JSON.toJSONString(mapList, SerializerFeature.DisableCircularReferenceDetect);

    System.out.println(jsonString);
    List<Map.Entry<String, List<String>>> parse = JSON.parseObject(jsonString, new TypeReference<List<Map.Entry<String, List<String>>>>() {});
    System.out.println(parse);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:Issue1583.java

示例7: doToModel

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
/**
 * 用于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;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:21,代码来源:DataColumnPairGroupServiceImpl.java

示例8: test_case2

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
public void test_case2() {
	String text = "{\"modules\":{}}";
	L1<?> r0 = JSONObject.parseObject(text, new TypeReference<L1>() {
	});
	assertEquals(JSONObject.class, r0.getModules().getClass());

	L1<?> r1 = JSONObject.parseObject(text, new TypeReference<L1<L2>>() {
	});
	assertEquals(L2.class, r1.getModules().getClass());

	L1 r2 = JSONObject.parseObject(text, new TypeReference<L1>() {
	});
	assertEquals(JSONObject.class, r2.getModules().getClass());

       L1<?> r3 = JSONObject.parseObject(text, new TypeReference<L1<L3>>() {
       });
       assertEquals(L3.class, r3.getModules().getClass());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:Bug_for_fushou.java

示例9: test_for_issue

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
public void test_for_issue() throws Exception {
    char[] chars = new char[128];
    Random random = new Random();
    for (int i = 0; i < chars.length; ++i) {
        chars[i] = (char) Math.abs((short) random.nextInt());
    }
    
    Map<String, char[]> map = new HashMap<String, char[]>();
    map.put("val", chars);
    
    String text = JSON.toJSONString(map);
    System.out.println(text);
    
    Map<String, char[]> map2 = JSON.parseObject(text, new TypeReference<HashMap<String, char[]>>() {});
    char[] chars2 = (char[]) map2.get("val");
    Assert.assertArrayEquals(chars2, chars);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:Issue215_char_array.java

示例10: hgetObject

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
@Override
public <T> T hgetObject(final String bizkey,final String nameSpace,final String field,
		TypeReference<T> type,final GetDataCallBack<T> gbs) {
   	final String key = CacheUtils.getKeyByNamespace(bizkey,nameSpace);
   	String res = hget(bizkey,nameSpace,field,null);
   	T rtn = null;
   	if(StringUtils.isNotEmpty(res)){
   		rtn = CacheUtils.parseObject(key,res, type);
   	}else{
   		if(gbs!=null){
   			rtn = gbs.invoke();
   		}
   		if(null!=rtn){
   			hsetObject(bizkey,nameSpace,field,rtn);
   		}
   	}
   	return rtn;
}
 
开发者ID:ningyu1,项目名称:jodis-client,代码行数:19,代码来源:RedisClientImpl.java

示例11: recordDetails

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
/**
 * 记录详情
 *
 * @param recordId
 * @return
 */
private GameBase.RecordDetailsResponse recordDetails(String recordId) {
    GameBase.RecordDetailsResponse.Builder recordResponse = GameBase.RecordDetailsResponse.newBuilder();
    ApiResponse<GameRecordInfoRepresentation> gameRecordResponse = JSON.parseObject(HttpUtil.urlConnectionByRsa(Constant.apiUrl + Constant.gamerecordInfoUrl + recordId, null),
            new TypeReference<ApiResponse<GameRecordInfoRepresentation>>() {
            });
    if (0 == gameRecordResponse.getCode()) {
        recordResponse.setErrorCode(GameBase.ErrorCode.SUCCESS);
        if (null != gameRecordResponse.getData().getData()) {
            List<Record> records = JSON.parseArray(new String(gameRecordResponse.getData().getData(), Charset.forName("utf-8")), Record.class);
            for (Record record : records) {
                GameBase.RoundItemRecord.Builder roundItemRecord = GameBase.RoundItemRecord.newBuilder();
                for (SeatRecord seatRecord : record.getSeatRecordList()) {
                    roundItemRecord.addUserRecord(GameBase.UserRecord.newBuilder().setID(seatRecord.getUserId())
                            .setNickname(seatRecord.getNickname()).setHead(seatRecord.getNickname()).setScore(seatRecord.getWinOrLose()).build());
                }
                recordResponse.addRoundItemRecord(roundItemRecord);
            }
        }
    } else {
        recordResponse.setErrorCode(GameBase.ErrorCode.ERROR_UNKNOW);
    }
    return recordResponse.build();
}
 
开发者ID:peng9627,项目名称:hall,代码行数:30,代码来源:HallClient.java

示例12: test_for_issue

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
public void test_for_issue() throws Exception {
    int[] values = new int[128];
    Random random = new Random();
    for (int i = 0; i < values.length; ++i) {
        values[i] = random.nextInt();
    }
    
    Map<String, int[]> map = new HashMap<String, int[]>();
    map.put("val", values);
    
    String text = JSON.toJSONString(map);
    System.out.println(text);
    
    Map<String, int[]> map2 = JSON.parseObject(text, new TypeReference<HashMap<String, int[]>>() {});
    int[] values2 = (int[]) map2.get("val");
    Assert.assertArrayEquals(values2, values);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:Issue215_int_array.java

示例13: call

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
/**
 * @Title: call
 * @Description: call类型,点对点发送接收消息
 * @param topicRoutingKey
 * @param serverName
 * @param bodyMsg
 * @param outTimeMillis
 * @throws Exception 设定文件
 * @return Map<String,Object>    返回类型
 */
public Map<String,Object> call(String topicRoutingKey,String serverName,Map<String,Object> bodyMsg,int outTimeMillis) throws Exception{
    Map<String,Object> sendMsg = new HashMap<String,Object>();
    sendMsg.put("mqkey",topicRoutingKey+"."+serverName);
    sendMsg.put("mqtype","call");
    sendMsg.put("mqbody",bodyMsg==null?new HashMap<String,Object>():bodyMsg);

    String topicMessage = JSON.toJSONString(sendMsg, JsonFilter.filter);
    Message message=new Message(topicMessage.getBytes("UTF-8"),new MessageProperties());

    RabbitTemplate directTemplate =new RabbitTemplate();
    directTemplate.setConnectionFactory(connectionFactory);
    directTemplate.setExchange(PropertyLoader.MQ_EXCHANGE);
    directTemplate.setReplyTimeout(outTimeMillis);

    Message reply=directTemplate.sendAndReceive(topicRoutingKey,message);
    if(reply==null){
        throw new Exception("waitting rabbitmq response timeout");
    }
    String body=new String(reply.getBody(),"UTF-8");
    Map<String,Object> reqMsgMap =JSON.parseObject(body,new TypeReference<Map<String, Object>>(){});
    LOG.info("back :"+reqMsgMap);
    reqMsgMap =JSON.parseObject(reqMsgMap.get("mqbody").toString(),new TypeReference<Map<String, Object>>(){});
    return reqMsgMap;
}
 
开发者ID:elves-project,项目名称:scheduler,代码行数:35,代码来源:MessageProducer.java

示例14: test_for_issue

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
public void test_for_issue() throws Exception {
    short[] values = new short[128];
    Random random = new Random();
    for (int i = 0; i < values.length; ++i) {
        values[i] = (short) random.nextInt();
    }
    
    Map<String, short[]> map = new HashMap<String, short[]>();
    map.put("val", values);
    
    String text = JSON.toJSONString(map);
    System.out.println(text);
    
    Map<String, short[]> map2 = JSON.parseObject(text, new TypeReference<HashMap<String, short[]>>() {});
    short[] values2 = (short[]) map2.get("val");
    Assert.assertArrayEquals(values2, values);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:Issue215_short_array.java

示例15: test_for_issue

import com.alibaba.fastjson.TypeReference; //导入依赖的package包/类
public void test_for_issue() throws Exception {
    float[] values = new float[128];
    Random random = new Random();
    for (int i = 0; i < values.length; ++i) {
        values[i] = random.nextFloat();
    }
    
    Map<String, float[]> map = new HashMap<String, float[]>();
    map.put("val", values);
    
    String text = JSON.toJSONString(map);
    System.out.println(text);
    
    Map<String, float[]> map2 = JSON.parseObject(text, new TypeReference<HashMap<String, float[]>>() {});
    float[] values2 = (float[]) map2.get("val");
    Assert.assertTrue(Arrays.equals(values2, values));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:Issue215_float_array.java


注:本文中的com.alibaba.fastjson.TypeReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。