com.jeesuite.common.json.JsonUtils类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中com.jeesuite.common.json.JsonUtils类的一些代码示例,展示了JsonUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonUtils类的具体详情如下:
包路径:com.jeesuite.common.json.JsonUtils
类名称:JsonUtils

JsonUtils介绍

暂无

代码示例

代码示例来源:origin: vakinge/jeesuite-libs

@Override
  public String toString() {
    return JsonUtils.toJson(this);
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

public static ClearCommand deserialize(String json) {
    return JsonUtils.toObject(json, ClearCommand.class);
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * 转换成格式化的json字符串
 * @param object
 * @return
 */
public static String toPrettyJson(Object object){
  try {			
    return getMapper().writerWithDefaultPrettyPrinter().writeValueAsString(object);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * 
 * @param jsonString
 * @param attrs (e.g:info.user.id)
 * @return
 */
public static String getJsonNodeValue(String jsonString, String attrs) {  
  return getJsonNodeValue(getNode(jsonString, null), attrs);
}

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * 
 * @param node
 * @param attrs (e.g:info.user.id)
 * @return
 */
public static String getJsonNodeValue(JsonNode node, String attrs) {  
  int index = attrs.indexOf('.');  
  if (index == -1) {  
    if (node != null && node.get(attrs) != null) {  
      return node.get(attrs).asText();
    }  
    return null;  
  } else {  
    String s1 = attrs.substring(0, index);  
    String s2 = attrs.substring(index + 1);  
    return getJsonNodeValue(node.get(s1), s2);  
  }  
}

代码示例来源:origin: vakinge/jeesuite-passport

public String toJsonString(){
  return JsonUtils.toJson(this);
}

代码示例来源:origin: vakinge/jeesuite-libs

@Override
  public void handleDataChange(String dataPath, Object data) throws Exception {
    if(data == null)return;
    JobConfig _jobConfig = JsonUtils.toObject(data.toString(), JobConfig.class);
    schedulerConfgs.put(jobName, _jobConfig);
  }
});

代码示例来源:origin: vakinge/jeesuite-passport

public static LoginUserInfo unsign(String jwt) {
  final JWTVerifier verifier = new JWTVerifier(SECRET);
  try {
    final Map<String,Object> claims= verifier.verify(jwt);
    if (claims.containsKey(PAYLOAD)&&claims.containsKey(USERID)) {
      String json = (String)claims.get(PAYLOAD);
      String userId = claims.get(USERID).toString();
      LoginUserInfo user = JsonUtils.getMapper().readValue(json,LoginUserInfo.class);
      if (userId.equals(user.getId().toString())){
        return user;
      }
    }
    return null;
  } catch (Exception e) {
    return null;
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

public String serialize() {
  return JsonUtils.toJson(this);
}

代码示例来源:origin: vakinge/jeesuite-libs

@Override
public Object deserialize(String topic, byte[] data) {
  try {
    if (data == null)
      return null;
    else{            	
      String jsonString = new String(data, StandardCharsets.UTF_8.name());
      try {
        return JsonUtils.toObject(jsonString, DefaultMessage.class);
      } catch (Exception e) {
        return jsonString;
      }
    }
  } catch (UnsupportedEncodingException e) {
    throw new SerializationException("Error when deserializing byte[] to string due to unsupported encoding UTF-8");
  }
}

代码示例来源:origin: vakinge/oneplatform

@Override
  public void run() {
    while (true) {
      if(System.currentTimeMillis() - startTime > VERIFY_WAIT_MILLIS){
        log.warn(" >>>> service registration status not verify,please check it!!!!");
        return;
      }
      try {
        List<InstanceInfo> serverInfos = eurekaClient.getInstancesByVipAddress(vipAddress, false);
        for (InstanceInfo nextServerInfo : serverInfos) {
          if(nextServerInfo.getIPAddr().equals(IpUtils.LOCAL_BACK_IP) || 
              nextServerInfo.getIPAddr().equals(IpUtils.getLocalIpAddr())){
            String instanceInfoJson = JsonUtils.getMapper().writerWithDefaultPrettyPrinter().writeValueAsString(nextServerInfo);
            log.info("verifying service registration with eureka finished,instance:\n{}",instanceInfoJson);
            return;
          }
        }
      } catch (Throwable e) {}
      try {Thread.sleep(5000);} catch (Exception e1) {}
      log.info("Waiting 5s... verifying service registration with eureka ...");
    }
  }
}).start();

代码示例来源:origin: vakinge/oneplatform

public String toJsonString(){
  return JsonUtils.toJson(this);
}

代码示例来源:origin: vakinge/jeesuite-passport

public static LoginSession getLoginSession(String sessionId){
  if(StringUtils.isBlank(sessionId))return null;
  String key = String.format(PassportConstants.SESSION_CACHE_KEY, sessionId);
  String json = AuthRedisClient.getInstance().getStr(key);
  return StringUtils.isBlank(json) ? null : JsonUtils.toObject(json, LoginSession.class);
}

代码示例来源:origin: vakinge/jeesuite-libs

public static void main(String[] args) {
    List<Object> list = new ArrayList<>();
    list.add(new Date());
    System.out.println(toJson(list));
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

@SuppressWarnings("rawtypes")
public static String ipToLocation(String ip) {
  if(isInnerIp(ip))return null;
  try {			
    String url = "http://ip.taobao.com/service/getIpInfo.php?ip="+ip;
    String content = HttpUtils.get(url).getBody();
    Map resp = JsonUtils.toObject(content, Map.class);
    if("0".equals(String.valueOf(resp.get("code")))){
      resp = (Map) resp.get("data");
      //String region = resp.get("region") == null ? "" : resp.get("region").toString();
      String city = resp.get("city") == null ? "" : resp.get("city").toString();
      return city;
    }
  } catch (Exception e) {}
  
  
  return null;
}

代码示例来源:origin: vakinge/jeesuite-libs

public void processResponse(ContainerRequestContext requestContext, ContainerResponseContext responseContext,
    ResourceInfo resourceInfo) {
  Object responseData = responseContext.getEntity();
  logger.info("response:\n",JsonUtils.toJson(responseData));
}

代码示例来源:origin: vakinge/jeesuite-libs

private synchronized JobConfig getConfigFromZK(String path,Stat stat){
  Object data = stat == null ? zkClient.readData(path) : zkClient.readData(path,stat);
  return data == null ? null : JsonUtils.toObject(data.toString(), JobConfig.class);
}

代码示例来源:origin: vakinge/jeesuite-libs

public static  void responseOutJsonp(HttpServletResponse response,String callbackFunName,Object jsonObject) {  
  //将实体对象转换为JSON Object转换  
  response.setCharacterEncoding("UTF-8");  
  response.setContentType("text/plain; charset=utf-8");  
  PrintWriter out = null;  
  
  String json = (jsonObject instanceof String) ? jsonObject.toString() : JsonUtils.toJson(jsonObject);
  String content = callbackFunName + "("+json+")";
  try {  
    out = response.getWriter();  
    out.append(content);  
  } catch (IOException e) {  
    e.printStackTrace();  
  } finally {  
    if (out != null) {  
      out.close();  
    }  
  }  
}

代码示例来源:origin: vakinge/jeesuite-libs

@Override
public void handleError(ClientHttpResponse response) throws IOException {
  int code = response.getRawStatusCode();
  String content = CharStreams.toString(new InputStreamReader(response.getBody(), StandardCharsets.UTF_8));
  WrapperResponseEntity entity = null;
  Map<?, ?> responseItmes = null;
  try {
    if(content.contains("code")){				
      entity = JsonUtils.toObject(content, WrapperResponseEntity.class);
    }else{
      responseItmes = JsonUtils.toObject(content, Map.class);
      String errorMsg = DEFAULT_ERROR_MSG;
      if(responseItmes != null && responseItmes.containsKey("message")){
        errorMsg = responseItmes.get("message").toString();
      }
      entity = new WrapperResponseEntity(500, errorMsg);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  if (entity != null) {
    throw new JeesuiteBaseException(entity.getCode(), entity.getMsg());
  } else {
    throw new JeesuiteBaseException(code, DEFAULT_ERROR_MSG);
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

private void commitToZK(){
  if(commited.get())return;
  Set<Entry<String, AtomicLong[]>> entrySet = producerStats.entrySet();
  for (Entry<String, AtomicLong[]> entry : entrySet) {
    AtomicLong[] nums = entry.getValue();
    ProducerStat stat = new ProducerStat(entry.getKey(), producerGroup, nums[0], nums[1], nums[2], nums[3]);
    zkClient.writeData(statPaths.get(entry.getKey()), JsonUtils.toJson(stat));
  }
  commited.set(true);
}

相关文章

微信公众号

最新文章

更多