本文整理匯總了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();
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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));
}