Java Code Examples for com.alibaba.fastjson.JSONObject#parseArray()

The following examples show how to use com.alibaba.fastjson.JSONObject#parseArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlinkWebClientBusiness.java    From PoseidonX with Apache License 2.0 7 votes vote down vote up
public static List<FlinkJobVerticeDTO> getJobVerticeDTOs(String yarnAppId, String jobId){
    List<FlinkJobVerticeDTO> flinkJobVerticeDTOs = Lists.newArrayList();

    String jobDetail = getJobDetail(yarnAppId, jobId);
    if(StringUtils.isBlank(jobDetail)){
        return null;
    }

    JSONObject jobDetailJSONObject  = JSONObject.parseObject(jobDetail);
    if(jobDetailJSONObject == null){
        return null;
    }

    String vertices = jobDetailJSONObject.getString("vertices");
    if(StringUtils.isBlank(vertices)){
        return null;
    }

    flinkJobVerticeDTOs = JSONObject.parseArray(vertices,FlinkJobVerticeDTO.class);
    return flinkJobVerticeDTOs;
}
 
Example 2
Source File: HBaseUtil.java    From DataLink with Apache License 2.0 6 votes vote down vote up
/**
 * 根据传入的MediaSourceInfo和表名,获取这个表下的所有列的元信息
 *
 * @param info
 * @param tableName
 * @return
 */
public static List<ColumnMeta> getColumns(MediaSourceInfo info, String tableName) {
    checkHbase(info);
    HBaseMediaSrcParameter parameter = info.getParameterObj();
    long zkId = parameter.getZkMediaSourceId();
    String znode = parameter.getZnodeParent();
    MediaSourceInfo zkInfo = dao.findMediaSourceById(zkId);
    checkZookeepr(zkInfo);
    ZkMediaSrcParameter zkParameter = zkInfo.getParameterObj();

    HBaseParameterVO vo = new HBaseParameterVO();
    vo.setTableName(tableName);
    vo.setZkAddress(zkParameter.getServers());
    vo.setPort(zkParameter.parsePort() + "");
    vo.setZnode(parameter.getZnodeParent());
    vo.setHbaseParameter(parameter);
    if (HBASE_SPECIFIED_NUM.get() > 0) {
        vo.setOnceFethAmount(HBASE_SPECIFIED_NUM.get());
    }
    String json = execute(vo, GET_COLUMNS_URL);
    if (json.equals(NULLJSON)) {
        throw new ErrorException(CodeContext.HBASE_COLUMNMETA_ERROR_CODE);
    }
    return JSONObject.parseArray(json, ColumnMeta.class);
}
 
Example 3
Source File: FlinkWebClientBusiness.java    From PoseidonX with Apache License 2.0 6 votes vote down vote up
private static List<FlinkMetricDto> getVerticeMetricsDtos(String yarnAppId, String jobId, String verticeId, List<String> metrics){
    String address = buildYarnProxyAddress(yarnAppId) + "/jobs/" + jobId + "/vertices/" + verticeId + "/metrics";
    String rs = "";
    try {
        Map<String, Object> params = Maps.newHashMap();
        params.put("get",StringUtils.join(metrics,","));
        rs = instance.get(address,params);

        if(StringUtils.isNotBlank(rs) && isJsonArray(rs)){
            List<FlinkMetricDto> flinkMetricDtos = JSONObject.parseArray(rs,FlinkMetricDto.class);
            return flinkMetricDtos;
        }else if(StringUtils.isNotBlank(rs) && isJson(rs)){
            FlinkMetricDto flinkMetricDto = JSONObject.parseObject(rs,FlinkMetricDto.class);
            return Lists.<FlinkMetricDto>newArrayList(flinkMetricDto);
        }else{
            return Lists.<FlinkMetricDto>newArrayList();
        }
    } catch (IOException e) {
    }
    return Lists.<FlinkMetricDto>newArrayList();
}
 
Example 4
Source File: AdminGoodsServiceImpl.java    From unimall with Apache License 2.0 6 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public String batchDelete(String idsJson, Long adminId) throws ServiceException {
    List<Long> ids = JSONObject.parseArray(idsJson, Long.class);
    if (CollectionUtils.isEmpty(ids)) {
        throw new AdminServiceException(ExceptionDefinition.GOODS_NOT_EXIST);
    }
    if (spuMapper.delete(new EntityWrapper<SpuDO>().in("id", ids)) <= 0) {
        throw new AdminServiceException(ExceptionDefinition.GOODS_NOT_EXIST);
    }
    List<Long> skuIds = skuMapper.selectSkuIdsBySpuIds(ids);
    cartMapper.delete(new EntityWrapper<CartDO>().in("sku_id", skuIds));
    skuMapper.delete(new EntityWrapper<SkuDO>().in("spu_id", ids));
    imgMapper.delete(new EntityWrapper<ImgDO>().in("biz_id", ids).eq("biz_type", BizType.GOODS.getCode()));
    spuAttributeMapper.delete(new EntityWrapper<SpuAttributeDO>().in("spu_id", ids));
    for (Long spuId : ids) {
        goodsBizService.clearGoodsCache(spuId);
    }
    return "ok";
}
 
Example 5
Source File: JobMenuService.java    From xmfcn-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 根据角色ID获取需要选中的菜单数据
 *
 * @param roleId
 * @return
 */
public List<JobMenu> getJobMenuRoles(long roleId, String roleCode) {
    List<JobMenu> list = null;
    String key = ConstantUtil.CACHE_KEY_PREFIX_MENU_ + roleId + roleCode;
    String cache = sysCommonService.getCache(key);
    list = JSONObject.parseArray(cache, JobMenu.class);
    if (list != null && list.size() > 0) {
        return list;
    }
    Map parms = new HashMap();
    parms.put("flag", 1);
    if (roleId > 0) {
        parms.put("roleId", roleId);
    }
    if (StringUtil.isNotBlank(roleCode)) {
        parms.put("roleCode", roleCode);
    }
    list = jobMenuDao.getRoleMenuList(parms);
    if (list != null && list.size() > 0) {
        sysCommonService.save(key, JSON.toJSONString(list), 30);
    }
    return list;
}
 
Example 6
Source File: GetServerApi.java    From LuckyFrameClient with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * ��ȡ��Ŀ�µ����й�������
 * @param projectid ��ĿID
 * @return ������������
 */
public static List<ProjectCaseParams> cgetParamsByProjectid(String projectid) {
	String result = HttpRequest.loadJSON(PREFIX+"/clientGetParamsByProjectId.do?projectId="+projectid);
	List<ProjectCaseParams> paramsList = JSONObject.parseArray(result, ProjectCaseParams.class);
	//�����������������ú���ʱ���Ƚ�������ת��
	for(ProjectCaseParams pcp:paramsList){
		pcp.setParamsValue(ParamsManageForSteps.paramsManage(pcp.getParamsValue()));
	}
	return paramsList;
}
 
Example 7
Source File: SerializeHelper.java    From jmqtt with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> deserializeList(byte[] bytes, Class<T> clazz){
    try{
        String json = JSONObject.toJSONString(bytes);
        List<T> result = JSONObject.parseArray(json,clazz);
        return result;
    }catch (Exception ex){
        log.warn("Deserialize failure,cause={}",ex);
    }
    return null;
}
 
Example 8
Source File: CacheComponent.java    From unimall with Apache License 2.0 5 votes vote down vote up
public <T> List<T> getHashArray(String hashName, String key, Class<T> clazz) {
    String o = (String) stringRedisTemplate.opsForHash().get(hashName, key);
    if (StringUtils.isEmpty(o)) {
        return null;
    }
    return JSONObject.parseArray(o, clazz);
}
 
Example 9
Source File: RedisService.java    From light-reading-cloud with MIT License 5 votes vote down vote up
public <T> List<T> getHashListVal(String key, String field, Class<T> c){
    Object val = this.hashOperations.get(key, field);
    if (val == null) {
        return null;
    }
    return JSONObject.parseArray(val.toString(), c);
}
 
Example 10
Source File: MessageController.java    From pmq with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/retryAll/failMessage")
@ResponseBody
public PublishMessageResponse retryAllFailMessage(@RequestParam("messageIds") String messageIds,long queueId) {
    List<String> consumerIdList = JSONObject.parseArray(messageIds, String.class);
    List<Long>ids=new ArrayList<>();
    for (String id:consumerIdList) {
        ids.add(Long.parseLong(id));
    }
    return uiMessageService.sendAllFailMessage(queueId, ids);
}
 
Example 11
Source File: SmartRedisService.java    From smart-admin with MIT License 5 votes vote down vote up
public <T> List<T> getList(String key, Class<T> clz) {
    Object json = this.get(key);
    if (json == null) {
        return Lists.newArrayList();
    }
    List<T> list = JSONObject.parseArray(json.toString(), clz);
    return list;
}
 
Example 12
Source File: WXJsonUtils.java    From weex with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> getList(String json, Class<T> clazz) {
  List<T> result = null;
  try {
    result = JSONObject.parseArray(json, clazz);
  } catch (Exception e) {
  }
  return result;
}
 
Example 13
Source File: FlinkWebClientBusiness.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
public static List<String> getTaskManagerDetail(String yarnAppId){
    List<String> taskManagerDetails = Lists.newArrayList();
    Set<String> taskManagerIds = Sets.newHashSet();

    String taskManagers = getTaskManagers(yarnAppId);
    if(StringUtils.isBlank(taskManagers)){
       return taskManagerDetails;
    }

    JSONObject taskManagersJSONObject  = JSONObject.parseObject(taskManagers);
    if(taskManagersJSONObject == null){
        return taskManagerDetails;
    }

    String taskmanagers = taskManagersJSONObject.getString("taskmanagers");
    if(StringUtils.isBlank(taskmanagers)){
        return taskManagerDetails;
    }

    JSONArray jSONArray = JSONObject.parseArray(taskmanagers);
    if(jSONArray!=null && jSONArray.size() > 0){
        int i=0;
        for(;i < jSONArray.size();){
            String id = jSONArray.getJSONObject(i).getString("id");
            if(StringUtils.isNotBlank(id)){
                taskManagerIds.add(id);
            }
            i++;
        }
    }
    return getTaskManagerDetail(yarnAppId, taskManagerIds);
}
 
Example 14
Source File: RedisService.java    From light-reading-cloud with MIT License 4 votes vote down vote up
public <T> List getCacheForList(String key, Class<T> c) {
    String cache = getCache(key);
    return JSONObject.parseArray(cache, c);
}
 
Example 15
Source File: TieBaImageIdMessageListener.java    From javabase with Apache License 2.0 4 votes vote down vote up
/**
 * 所有帖子ID,部分帖子包含图片
 * @param message
 * @param bytes
    */
public void onMessage(Message message, byte[] bytes) {
	try {
		String jsonStr = WebmagicService.getString(message.getBody());
		List<ContentBean> pageList = JSONObject.parseArray(jsonStr, ContentBean.class);
		if (pageList != null && pageList.size() > 0) {
			String tiebaName = pageList.get(0).getName();
			//包含图片的key
			byte[] imageKey = getByte(TIEBA_CONTENT_IMAGE_KEY + tiebaName);
			//不包含图片的key
			byte[] noImageKey = getByte(TieBaNoImageIdMessageListener.TIEBA_CONTENT_NO_IMAGE_KEY + tiebaName);
			log.info("{}:待同步pageID数量:{}", tiebaName, pageList.size());
			//可能包含图片的page
			List<ContentBean> imagePageList = new ArrayList<>();
			//没有被缓存的page
			List<String> notCachePageImageList = new ArrayList<>();
			removeExistId(pageList, imagePageList, notCachePageImageList, imageKey, noImageKey);
			log.info("{}:去除已同步pageID后数量:{}", tiebaName, notCachePageImageList.size());
			//包含图片的map
			ConcurrentHashMap<byte[], byte[]> map = contentImageProcessor.start(notCachePageImageList, tiebaName);
			redisTemplate.executePipelined(new RedisCallback<Object>() {
				@Override
				public Object doInRedis(RedisConnection redisConnection) throws DataAccessException {
					//保存所有帖子 tieba_content_image_4813146001
					if (map.size() > 0)
						redisConnection.mSet(map);
					// 存储帖子最新更新时间
					byte[] timeKey = getByte(TIEBA_CONTENT_UPDATE_TIME_KEY + tiebaName);
					//可能包含图片的
					for (ContentBean contentBean : imagePageList) {
						Set<String> set = CollectionUtils.convertMapByteToSetString(map);
						//没有被缓存的
						if (set.contains(TIEBA_CONTENT_IMAGE_KEY + contentBean.getId())) {
							//key=tieba_content_image_李毅
							redisConnection.sAdd(imageKey, WebmagicService.getByte(contentBean.getId()));
							//key=tieba_content_image_4813146001
							redisConnection.zAdd(timeKey, Double.parseDouble(contentBean.getDate()), WebmagicService.getByte(contentBean.getId()));
						}
					}
					log.info("ScheduleTask.run={}", true);
					return null;
				}
			});
		}
	}catch (Exception e){
		log.error("onMessage error",e);
	}finally {
		ScheduleTask.run = true;
	}
}
 
Example 16
Source File: ListTypeHandler.java    From server with MIT License 4 votes vote down vote up
@Override
public List getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
    return JSONObject.parseArray(callableStatement.getString(i), getTypeClass());
}
 
Example 17
Source File: ListTypeHandler.java    From server with MIT License 4 votes vote down vote up
@Override
public List getNullableResult(ResultSet resultSet, int i) throws SQLException {
    return JSONObject.parseArray(resultSet.getString(i), getTypeClass());
}
 
Example 18
Source File: EventParserJsonTest.java    From gsc-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public synchronized void testEventParser() {

  Wallet.setAddressPreFixByte(Constant.ADD_PRE_FIX_BYTE);

  String eventSign = "eventBytesL(address,bytes,bytes32,uint256,string)";

  String abiStr = "[{\"constant\":false,\"inputs\":[{\"name\":\"_address\",\"type\":\"address\"},{\"name\":\"_random\",\"type\":\"bytes\"}],\"name\":\"randomNum\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":true,\"inputs\":[{\"indexed\":true,\"name\":\"addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"random\",\"type\":\"bytes\"},{\"indexed\":false,\"name\":\"last1\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"t2\",\"type\":\"uint256\"}],\"name\":\"eventAnonymous\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"random\",\"type\":\"bytes\"},{\"indexed\":true,\"name\":\"last1\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"t2\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"str\",\"type\":\"string\"}],\"name\":\"eventBytesL\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"random\",\"type\":\"bytes\"},{\"indexed\":false,\"name\":\"last1\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"t2\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"str\",\"type\":\"string\"}],\"name\":\"eventBytes\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"random\",\"type\":\"bytes\"},{\"indexed\":false,\"name\":\"\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"last1\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"t2\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"str\",\"type\":\"string\"}],\"name\":\"eventByteArr\",\"type\":\"event\"}]";

  String dataStr = "0x000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000020109000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a6162636465666731323300000000000000000000000000000000000000000000";

  byte[] data = ByteArray.fromHexString(dataStr);
  List<byte[]> topicList = new LinkedList<>();
  topicList.add(Hash.sha3(eventSign.getBytes()));
  topicList.add(ByteArray
      .fromHexString("0xb7685f178b1c93df3422f7bfcb61ae2c6f66d0947bb9eb293259c231b986b81b"));

  JSONArray entryArr = JSONObject.parseArray(abiStr);
  JSONObject entry = new JSONObject();

  for (int i = 0; i < entryArr.size(); i++) {
    JSONObject e = entryArr.getJSONObject(i);
    System.out.println(e.getString("name"));
    if (e.getString("name") != null) {
      if (e.getString("name").equalsIgnoreCase("eventBytesL")) {
        entry = e;
        break;
      }
    }
  }

  Assert.assertNotNull(entry);
  Map<String, String> dataMap = ContractEventParserJson.parseEventData(data, topicList, entry);
  Map<String, String> topicMap = ContractEventParserJson.parseTopics(topicList, entry);

  Assert.assertEquals(dataMap.get("0"), "GSChnYfqiK4FwKgjaweaJggWz1P9yrb1xNix");
  Assert.assertEquals(dataMap.get("addr"), "GSChnYfqiK4FwKgjaweaJggWz1P9yrb1xNix");

  Assert.assertEquals(dataMap.get("1"), "0109");
  Assert.assertEquals(dataMap.get("random"), "0109");

  Assert.assertEquals(topicMap.get("2"),
      "b7685f178b1c93df3422f7bfcb61ae2c6f66d0947bb9eb293259c231b986b81b");
  Assert.assertEquals(topicMap.get("last1"),
      "b7685f178b1c93df3422f7bfcb61ae2c6f66d0947bb9eb293259c231b986b81b");

  Assert.assertEquals(dataMap.get("3"), "1");
  Assert.assertEquals(dataMap.get("t2"), "1");

  Assert.assertEquals(dataMap.get("4"), "abcdefg123");
  Assert.assertEquals(dataMap.get("str"), "abcdefg123");

}
 
Example 19
Source File: GetServerApi.java    From LuckyFrameClient with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * ͨ���ƻ�ID��ȡ������������
 * @param planId ���Լƻ�ID
 * @return ��������List
 */
public static List<ProjectCase> getCasesbyplanId(int planId) {
	String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListByPlanId.do?planId=" + planId);
	return JSONObject.parseArray(result, ProjectCase.class);
}
 
Example 20
Source File: GetServerApi.java    From LuckyFrameClient with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * ͨ���ƻ����ƻ�ȡ������������
 * @param name ���Լƻ�����
 * @return ��������List
 */
public static List<ProjectCase> getCasesbyplanname(String name) {
	String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListByPlanName.do?planName=" + name);
	return JSONObject.parseArray(result, ProjectCase.class);
}