Java 类com.alibaba.fastjson.TypeReference 实例源码

项目:boohee_v5.6    文件:DownloadHelper.java   
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();
    }
}
项目:scheduler    文件:ElvesMqMessage.java   
/**
 * @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;
    }
}
项目:jodis-client    文件:RedisClientImpl.java   
@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;
}
项目:GitHub    文件:BigStringFieldTest.java   
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);    
    }
}
项目:atlas    文件:AtlasProguardHelper.java   
@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;
}
项目:supervisor    文件:ElvesMqMessage.java   
/**
 * @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;
    }
}
项目:cmdbproxy    文件:ElvesMqMessage.java   
/**
 * @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;
    }
}
项目:GitHub    文件:Issue1583.java   
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);
}
项目:otter-G    文件:DataColumnPairGroupServiceImpl.java   
/**
 * 用于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;
}
项目:GitHub    文件:Bug_for_fushou.java   
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());
}
项目:GitHub    文件:Issue215_char_array.java   
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);
}
项目:jodis-client    文件:RedisClientImpl.java   
@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;
}
项目:hall    文件:HallClient.java   
/**
 * 记录详情
 *
 * @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();
}
项目:GitHub    文件:Issue215_int_array.java   
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);
}
项目:scheduler    文件:MessageProducer.java   
/**
 * @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;
}
项目:GitHub    文件:Issue215_short_array.java   
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);
}
项目:GitHub    文件:Issue215_float_array.java   
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));
}
项目:openapi    文件:ElvesMqMessage.java   
/**
 * @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;
    }
}
项目:boohee_v5.6    文件:RadarPresenter.java   
private void initView(JSONObject jsonObject) {
    if (jsonObject != null) {
        this.mActivity.hideEmptyView();
        Radar radar = (Radar) extractData(jsonObject.optString("radar"), Radar.class);
        if (User.WEEK_REPORT_STATUS_UPDATED.equals(this.status)) {
            this.mActivity.setRadar(radar, true);
        } else {
            this.mActivity.setRadar(radar, false);
        }
        this.mActivity.setDietary((Dietary) extractData(jsonObject.optJSONObject("nutrition")
                .optString("dietary"), Dietary.class));
        this.mActivity.setElement((Element) extractData(jsonObject.optJSONObject("nutrition")
                .optString("element"), Element.class));
        this.mActivity.setSpirit((Spirit) extractData(jsonObject.optString("spirit"), Spirit
                .class));
        this.mActivity.setBalance((Balance) extractData(jsonObject.optString("balance"),
                Balance.class));
        this.mActivity.setSports((Sports) extractData(jsonObject.optString("sports"), Sports
                .class));
        this.mActivity.setSocial((Social) extractData(jsonObject.optString("social"), Social
                .class));
        this.mActivity.setSummary((Map) FastJsonUtils.fromJson(jsonObject.optString
                ("summary"), new TypeReference<Map<String, String>>() {
        }));
    }
}
项目:GitHub    文件:TypeReferenceTest8.java   
public void test_typeRef() throws Exception {
    TypeReference<Map<String, Entity>> typeRef = new TypeReference<Map<String, Entity>>() {
    };

    Map<String, Entity> map = JSON.parseObject(
            "{\"value\":{\"id\":\"abc\",\"list\":[{\"id\":123}]}}", typeRef);

    Entity entity = map.get("value");
    Assert.assertNotNull(entity);
    Assert.assertEquals("abc", entity.getId());
    Assert.assertEquals(1, entity.getList().length);
    Assert.assertEquals(123, entity.getList()[0].getId());
}
项目:hall    文件:HallClient.java   
/**
 * 游戏记录
 *
 * @return
 */
private GameBase.RecordResponse gameRecord() {
    GameBase.RecordResponse.Builder recordResponse = GameBase.RecordResponse.newBuilder();
    jsonObject.clear();
    jsonObject.put("userId", userId);
    ApiResponse<List<GameRecordRepresentation>> gameRecordResponse = JSON.parseObject(HttpUtil.urlConnectionByRsa(Constant.apiUrl + Constant.gamerecordListUrl, jsonObject.toJSONString()),
            new TypeReference<ApiResponse<List<GameRecordRepresentation>>>() {
            });
    Map<GameType, GameBase.GameRecord.Builder> gameRecords = new HashMap<>();
    if (0 == gameRecordResponse.getCode()) {
        for (GameRecordRepresentation gameRecordRepresentation : gameRecordResponse.getData()) {
            if (!gameRecords.containsKey(gameRecordRepresentation.getGameType())) {
                gameRecords.put(gameRecordRepresentation.getGameType(), GameBase.GameRecord.newBuilder()
                        .setGameType(GameBase.GameType.forNumber(gameRecordRepresentation.getGameType().ordinal())));
            }
            GameBase.Record.Builder record = GameBase.Record.newBuilder();
            record.setRecordId(gameRecordRepresentation.getId());
            record.setRoomNo(gameRecordRepresentation.getRoomNo() + "");
            record.setGameCount(gameRecordRepresentation.getGameCount());
            record.setDateTime(gameRecordRepresentation.getCreateDate().getTime());
            if (null != gameRecordRepresentation.getsData()) {
                List<TotalScore> totalScores = JSON.parseArray(new String(gameRecordRepresentation.getsData(), Charset.forName("utf-8")), TotalScore.class);
                for (TotalScore totalScore : totalScores) {
                    record.addUserRecord(GameBase.UserRecord.newBuilder().setNickname(totalScore.getNickname())
                            .setHead(totalScore.getHead()).setID(totalScore.getUserId()).setScore(totalScore.getScore()));
                }
            }
            gameRecords.get(gameRecordRepresentation.getGameType()).addRecords(record);
        }
        gameRecords.forEach(new BiConsumer<GameType, GameBase.GameRecord.Builder>() {
            @Override
            public void accept(GameType gameType, GameBase.GameRecord.Builder builder) {
                recordResponse.addGameRecords(builder);
            }
        });
    }
    return recordResponse.build();
}
项目:GitHub    文件:Issue1036.java   
/**
 * @see BeanToArrayTest3_private#test_array()
 * @see com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer#parseField
 * */
public void test_for_issue() throws Exception {
    NullPointerException exception = new NullPointerException("test");
    Result<String> result = new Result<String>();
    result.setException(exception);

    String json = JSON.toJSONString(result);

    Result<String> a = JSON.parseObject(json, new TypeReference<Result<String>>() {
    });

    Assert.assertEquals("test", a.getException().getMessage());
}
项目:GitHub    文件:IntFieldTest2.java   
public void test_model_map() throws Exception {
    String text = "{\"model\":{\"id\":-1001,\"id2\":-1002}}";

    JSONReader reader = new JSONReader(new StringReader(text));
    Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
    });
    Model model2 = map.get("model");
    Assert.assertEquals(-1001, model2.id);
    Assert.assertEquals(-1002, model2.id2);
    reader.close();
}
项目:GitHub    文件:Issue1480.java   
public void test_for_issue() throws Exception {

        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        map.put(1,10);
        map.put(2,4);
        map.put(3,5);
        map.put(4,5);
        map.put(37306,98);
        map.put(36796,9);

        String json = JSON.toJSONString(map);
        System.out.println(json);
        Assert.assertEquals("{1:10,2:4,3:5,4:5,37306:98,36796:9}",json);

        Map<Integer,Integer> map1 = JSON.parseObject(json,new TypeReference<HashMap<Integer,Integer>>() {});

        Assert.assertEquals(map1.get(Integer.valueOf(1)),Integer.valueOf(10));
        Assert.assertEquals(map1.get(Integer.valueOf(2)),Integer.valueOf(4));
        Assert.assertEquals(map1.get(Integer.valueOf(3)),Integer.valueOf(5));
        Assert.assertEquals(map1.get(Integer.valueOf(4)),Integer.valueOf(5));
        Assert.assertEquals(map1.get(Integer.valueOf(37306)),Integer.valueOf(98));
        Assert.assertEquals(map1.get(Integer.valueOf(36796)),Integer.valueOf(9));

        JSONObject map2 = JSON.parseObject("{35504:1,1:10,2:4,3:5,4:5,37306:98,36796:9\n" + "}");

        Assert.assertEquals(map2.get(Integer.valueOf(1)),Integer.valueOf(10));
        Assert.assertEquals(map2.get(Integer.valueOf(2)),Integer.valueOf(4));
        Assert.assertEquals(map2.get(Integer.valueOf(3)),Integer.valueOf(5));
        Assert.assertEquals(map2.get(Integer.valueOf(4)),Integer.valueOf(5));
        Assert.assertEquals(map2.get(Integer.valueOf(37306)),Integer.valueOf(98));
        Assert.assertEquals(map2.get(Integer.valueOf(36796)),Integer.valueOf(9));

    }
项目:GitHub    文件:TypeReferenceTest4.java   
public void test_typeRef() throws Exception {
    TypeReference<VO<List<A>>> typeRef = new TypeReference<VO<List<A>>>() {
    };

    VO<List<A>> vo = JSON.parseObject("{\"list\":[{\"id\":123}]}", typeRef);

    Assert.assertEquals(123, vo.getList().get(0).getId());
}
项目:GitHub    文件:Issue1400.java   
public void test_for_issue() throws Exception {
    TypeReference tr = new TypeReference<Resource<ArrayList<App>>>(){};
    Test test = new Test(tr);
    Resource resource = test.resource;
    Assert.assertEquals(1,resource.ret);
    Assert.assertEquals("ok",resource.message);
    List<App> data =(List<App>) resource.data;
    Assert.assertEquals(2,data.size());
    App app1 = data.get(0);
    Assert.assertEquals("11c53f541dee4f5bbc4f75f99002278c",app1.appId);
}
项目:GitHub    文件:TypeReferenceTest5.java   
public void test_typeRef() throws Exception {
    TypeReference<A<B>> typeRef = new TypeReference<A<B>>() {
    };

    A<B> a = JSON.parseObject("{\"body\":{\"id\":123}}", typeRef);

    B b = a.getBody();
    Assert.assertEquals(123, b.get("id"));
}
项目:GitHub    文件:DefaultExtJSONParser_parseArray_2.java   
public void test_0() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("[['1']]");
    parser.config(Feature.AllowISO8601DateFormat, false);
    List<List<Integer>> list = (List<List<Integer>>) parser.parseArrayWithType(new TypeReference<List<List<Integer>>>() {
    }.getType());
    Assert.assertEquals(new Integer(1), list.get(0).get(0));
}
项目:GitHub    文件:Bug_for_fushou.java   
public void test_case1() {
    String text = "{\"modules\":{}}";
    L1<?> r1 = JSONObject.parseObject(text, new TypeReference<L1<L2>>() {
    });
    assertEquals(true, r1.getModules() instanceof L2);

    L1 r2 = JSONObject.parseObject(text, new TypeReference<L1>() {
    });
    assertEquals(true, r2.getModules() instanceof JSONObject);
    assertEquals(false, r2.getModules() instanceof L2);
}
项目:supervisor    文件:UpdateBindDataTimer.java   
public void update(){
    List<App> apps=appServiceImpl.getAllApp();
    boolean flag=false;
    for(App app:apps){
        if(StringUtils.isNotBlank(app.getBindUrl())){
            try {
                String data = HttpUtil.sendGet(app.getBindUrl(),null);
                Map<String,String> rs = JSON.parseObject(data,new TypeReference<Map<String,String>>(){});
                List<Map<String,String>> dt =JSON.parseObject(rs.get("data"),new TypeReference<List<Map<String,String>>>(){});

                List<String> ips=new ArrayList<String>();
                for(Map m:dt){
                    if(null!=m.get("ip")&&StringUtils.isNotBlank(m.get("ip").toString())){
                        ips.add(m.get("ip").toString());
                    }
                }
                LOG.info("get agent from url:"+JSON.toJSONString(ips));
                if(StringUtils.isNotBlank(data)){
                    appServiceImpl.reBindAgent(app.getAppId(),ips);
                    if(!flag){
                        flag=true;
                    }
                }else{
                    LOG.error("url return data is empty,app:"+app.getInstruct()+",url:"+app.getBindUrl());
                }
            }catch (Exception e){
                LOG.error("update app bind agent exception,app:"+app.getInstruct()+",url:"+app.getBindUrl()+",msg:"+ ExceptionUtil.getStackTraceAsString(e));
            }
        }
    }
    //如果重新绑定数据成功,则通知heartbeat
    if(flag){
        appServiceImpl.noticeHeartbeat();
    }
}
项目:JSONParserMapTest    文件:MainActivity.java   
/**
 * fastjson解析Map
 */
private void fastJsonTest() {
    LinkedHashMap<CategoryEntity, List<CategoryEntity>> linkedHashMap = createMap();
    String s = FastJsonUtil.getInstance().toJson(linkedHashMap);
    LOG.D(TAG, "fastJson = " + s);

    LinkedHashMap<CategoryEntity, List<CategoryEntity>> parseHashMap =
            FastJsonUtil.getInstance().fromJson(
                    s,
                    new TypeReference<LinkedHashMap<CategoryEntity, List<CategoryEntity>>>() {
                    }.getType());

    LOG.D(TAG, "fastJson json2 = " + parseHashMap.toString());
}
项目:GitHub    文件:JSONReaderError.java   
public void test_reader_error_3() throws Exception {
    Exception error = null;
    try {
        JSONReader reader = new JSONReader(new StringReader("{\"model\":{\"id\":\"aa\",\"name\":\"wenshao\"}["));
        Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {});
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:DefaultExtJSONParser_parseArray.java   
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));
}
项目:GitHub    文件:ReaderLongFieldTest.java   
public void test_long_normal_2() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("{\"model\":{\"value\":3001,\"value2\":-4001}}"));
    Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
    });
    Model model = map.get("model");
    Assert.assertEquals(3001L, model.value);
    Assert.assertEquals(-4001L, model.value2);
    reader.close();
}
项目:GitHub    文件:ReaderBooleanFieldTest.java   
public void test_bool_normal_2() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("{\"model\":{\"value\":false,\"value2\":true}}"));
    Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {});
    Model model = map.get("model");
    Assert.assertFalse(model.value);
    Assert.assertTrue(model.value2);
    reader.close();
}
项目:GitHub    文件:EnumFieldTest.java   
public void test_map() throws Exception {
    JSONReader read = new JSONReader(new StringReader("{\"model\":{\"value\":\"A\",\"value1\":\"B\"}}"));
    Map<String, Model> map = read.readObject(new TypeReference<Map<String, Model>>(){});
    Model model = (Model) map.get("model");
    Assert.assertEquals(Type.A, model.value);
    Assert.assertEquals(Type.B, model.value1);
    read.close();
}
项目:GitHub    文件:DefaultObjectDeserializerTest5.java   
public void test_error() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("[]", new TypeReference<Map<Object, Object>>() {
        });
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:DefaultObjectDeserializerTest5.java   
public void test_error_2() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject(",]", new TypeReference<Map<Object, Object>>() {
        });
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:TypeUtilsTest2.java   
public void test_0() throws Exception {
    Assert.assertNull(TypeUtils.cast("", Entity.class, null));
    Assert.assertNull(TypeUtils.cast("", Type.class, null));
    Assert.assertNull(TypeUtils.cast("", Byte.class, null));
    Assert.assertNull(TypeUtils.cast("", Short.class, null));
    Assert.assertNull(TypeUtils.cast("", Integer.class, null));
    Assert.assertNull(TypeUtils.cast("", Long.class, null));
    Assert.assertNull(TypeUtils.cast("", Float.class, null));
    Assert.assertNull(TypeUtils.cast("", Double.class, null));
    Assert.assertNull(TypeUtils.cast("", Character.class, null));
    Assert.assertNull(TypeUtils.cast("", java.util.Date.class, null));
    Assert.assertNull(TypeUtils.cast("", java.sql.Date.class, null));
    Assert.assertNull(TypeUtils.cast("", java.sql.Timestamp.class, null));

    Assert.assertNull(TypeUtils.castToChar(""));
    Assert.assertNull(TypeUtils.castToChar(null));
    Assert.assertEquals('A', TypeUtils.castToChar('A').charValue());
    Assert.assertEquals('A', TypeUtils.castToChar("A").charValue());

    Assert.assertNull(TypeUtils.castToBigDecimal(""));
    Assert.assertNull(TypeUtils.castToBigInteger(""));
    Assert.assertNull(TypeUtils.castToBoolean(""));
    Assert.assertNull(TypeUtils.castToEnum("", Type.class, null));

    Assert.assertEquals(null, TypeUtils.cast("", new TypeReference<Pair<Object, Object>>() {

    }.getType(), null));
}
项目:scheduler    文件:ElvesMqMessage.java   
/**
 * @Title: parse
 * @Description: 解析数据
 * @param elvesMsg 设定文件
 * @return void    返回类型
 */
private void parse(Map<String,Object> elvesMsg){
    this.mqkey = elvesMsg.get("mqkey").toString().trim();
    this.mqtype = elvesMsg.get("mqtype").toString().trim();
    if(null!=elvesMsg.get("mqbody")){
        this.mqbody = JSON.parseObject(elvesMsg.get("mqbody").toString().trim(),new TypeReference<Map<String, Object>>(){});
    }else{
        this.mqbody =new HashMap<String, Object>();
    }
    this.fromModule = mqkey.split("[.]")[0];
    this.toModule = mqkey.split("[.]")[1];
    this.action = mqkey.split("[.]")[2];
}