本文整理汇总了Java中com.mpush.tools.Jsons.fromJson方法的典型用法代码示例。如果您正苦于以下问题:Java Jsons.fromJson方法的具体用法?Java Jsons.fromJson怎么用?Java Jsons.fromJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mpush.tools.Jsons
的用法示例。
在下文中一共展示了Jsons.fromJson方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String body = new String(readBody(httpExchange), Constants.UTF_8);
Map<String, Object> params = Jsons.fromJson(body, Map.class);
sendPush(params);
byte[] data = "服务已经开始推送,请注意查收消息".getBytes(Constants.UTF_8);
httpExchange.getResponseHeaders().set("Content-Type", "text/plain; charset=utf-8");
httpExchange.sendResponseHeaders(200, data.length);//200, content-length
OutputStream out = httpExchange.getResponseBody();
out.write(data);
out.close();
httpExchange.close();
}
示例2: receive
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
@Override
public void receive(String topic, Object message) {
if (getKickChannel().equals(topic)) {
KickRemoteMsg msg = Jsons.fromJson(message.toString(), MQKickRemoteMsg.class);
if (msg != null) {
onReceiveKickRemoteMsg(msg);
} else {
Logs.CONN.warn("receive an error kick message={}", message);
}
} else {
Logs.CONN.warn("receive an error redis channel={}", topic);
}
}
示例3: loadFormFile
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
private synchronized void loadFormFile() {
try {
long lastModified = Files.getLastModifiedTime(cacheFile).toMillis();
if (this.lastModified < lastModified) {
byte[] bytes = Files.readAllBytes(cacheFile);
if (bytes != null && bytes.length > 0) {
cache = Jsons.fromJson(bytes, ConcurrentHashMap.class);
}
this.lastModified = lastModified;
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: test
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
@Test
public void test() {
User user = new User("huang", 18, new Date());
cluster.set("huang", Jsons.toJson(user));
String ret = cluster.get("huang");
User newUser = Jsons.fromJson(ret, User.class);
System.out.println(ToStringBuilder.reflectionToString(newUser, ToStringStyle.JSON_STYLE));
}
示例5: get
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
/**
* @param key
* @param clazz
* @return
*/
@SuppressWarnings("unchecked")
public <T> T get(String key, Class<T> clazz) {
String value = call(jedis -> jedis.get(key), null);
if (value == null) return null;
if (clazz == String.class) return (T) value;
return Jsons.fromJson(value, clazz);
}
示例6: hget
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T hget(String key, String field, Class<T> clazz) {
String value = call(jedis -> jedis.hget(key, field), null);
if (value == null) return null;
if (clazz == String.class) return (T) value;
return Jsons.fromJson(value, clazz);
}
示例7: lpop
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
/**
* 移除并且返回 key 对应的 list 的第一个元素
*/
@SuppressWarnings("unchecked")
public <T> T lpop(String key, Class<T> clazz) {
String value = call(jedis -> jedis.lpop(key), null);
if (value == null) return null;
if (clazz == String.class) return (T) value;
return Jsons.fromJson(value, clazz);
}
示例8: rpop
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
/**
* 从队列的右边出队一个元素
*/
@SuppressWarnings("unchecked")
public <T> T rpop(String key, Class<T> clazz) {
String value = call(jedis -> jedis.rpop(key), null);
if (value == null) return null;
if (clazz == String.class) return (T) value;
return Jsons.fromJson(value, clazz);
}
示例9: fromJson
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
public static GatewayPushResult fromJson(String json) {
if (json == null) return null;
return Jsons.fromJson(json, GatewayPushResult.class);
}
示例10: decodeSet
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
private Set<String> decodeSet(ByteBuf body) {
String json = decodeString(body);
if (json == null) return null;
return Jsons.fromJson(json, new TypeReference<Set<String>>() {
}.getType());
}
示例11: decodeFrame
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
public static Packet decodeFrame(String frame) throws Exception {
if (frame == null) return null;
return Jsons.fromJson(frame, JsonPacket.class);
}
示例12: fromJson
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
@Override
public <T> T fromJson(String json, Class<T> clazz) {
return Jsons.fromJson(json, clazz);
}
示例13: get
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
@Override
public <T> T get(String key, Class<T> tClass) {
Object obj = cache.get(key);
if (obj == null) return null;
return Jsons.fromJson(obj.toString(), tClass);
}
示例14: hget
import com.mpush.tools.Jsons; //导入方法依赖的package包/类
@Override
public <T> T hget(String key, String field, Class<T> tClass) {
Object obj = ((Map) cache.computeIfAbsent(key, k -> new ConcurrentHashMap<>())).get(field);
if (obj == null) return null;
return Jsons.fromJson(obj.toString(), tClass);
}