本文整理汇总了Java中org.nutz.json.JsonFormat类的典型用法代码示例。如果您正苦于以下问题:Java JsonFormat类的具体用法?Java JsonFormat怎么用?Java JsonFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonFormat类属于org.nutz.json包,在下文中一共展示了JsonFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntityBy
import org.nutz.json.JsonFormat; //导入依赖的package包/类
/**
* 根据一个对象获取实体
* <p>
* 对象如果是集合或者数组,则取其第一个元素进行判断
*
* @param obj
* 对象
* @return 实体
*/
@SuppressWarnings("unchecked")
public Entity<?> getEntityBy(Object obj) {
// 正常的构建一个 Entity
Object first = Lang.first(obj);
// 对象为空,不能构建实体
if (first == null)
return null;
// 这是一个 Map,试图构建一个 entity
if (first instanceof Map<?, ?>) {
Object tableName = ((Map<String, ?>) first).get(".table");
if (null == tableName)
throw Lang.makeThrow( "Can not insert map without key '.table' : \n%s",
Json.toJson(first, JsonFormat.forLook()));
return makeEntity(tableName.toString(), (Map<String, ?>) first);
}
// 作为 POJO 构建
return getEntity(first.getClass());
}
示例2: push
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public void push(final WxInMsg in) {
ExecutorService es = this.es;
if (es == null || es.isShutdown()) {
log.info("WxHistoryService.queue is shutdown, ignore push");
return;
}
es.submit(new Runnable() {
public void run() {
try {
final WxMsgHistory history = new WxMsgHistory(in.getMsgId(),in.getFromUserName(), in.getMsgType(), 0, in.getCreateTime()*1000L);
ExtDaos.ext(dao, in.getToUserName()).insert(history);
resourceService.put(in.getToUserName(), history.getMsgkey(), Json.toJson(in, JsonFormat.compact()));
} catch (Throwable e) {
log.info("record in msg fail", e);
}
}
});
}
示例3: upload
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@At({"/iot/device/?/sensor/?/datapoints", "/v1.1/device/?/sensor/?/datapoints"})
@POST
@AdaptBy(type=VoidAdaptor.class)
@Ok("void")
public void upload(String device_id, String sensor_id, InputStream in, @Attr(Zs.UID)long userId, HttpServletResponse resp) throws IOException {
IotSensor sensor = dao.fetch(IotSensor.class, Cnd.where("deviceId", "=", device_id).and(Zs.UID, "=", userId).and("id", "=", sensor_id));
if (sensor == null) {
resp.setStatus(406);
resp.getWriter().write(Iots.NOTFOUND);
return;
}
if (sensor.getLastUpdateTime() != null && System.currentTimeMillis() - sensor.getLastUpdateTime().getTime() < Iots.Limit_Sensor_Update_Interval * 1000 ) {
resp.setStatus(406);
resp.getWriter().write(Iots.TOOFAST);
return ; // too fast
}
SensorUploadResult re = iotSensorService.upload(sensor, in);
if (re.err == null)
return;
resp.setStatus(406);
Mvcs.write(resp, re, JsonFormat.compact());
}
示例4: call
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public Object call(Object[] paras, Context ctx) {
switch (paras.length) {
case 1:
return Json.toJson(paras[0], JsonFormat.compact());
case 2:
Object t = paras[1];
if (t != null && t instanceof String) {
if ("full".equals(t)) {
return Json.toJson(paras[0], JsonFormat.full());
}
if ("nice".equals(t)) {
return Json.toJson(paras[0], JsonFormat.nice());
}
if ("compact".equals(t)) {
return Json.toJson(paras[0], JsonFormat.compact());
}
if ("forLook".equals(t)) {
return Json.toJson(paras[0], JsonFormat.forLook());
}
if ("tidy".equals(t)) {
return Json.toJson(paras[0], JsonFormat.tidy());
}
}
}
throw new BeetlException(BeetlException.FUNCTION_INVALID);
}
示例5: set
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public void set(PreparedStatement stat, Object obj, int index) throws SQLException {
if (null == obj) {
stat.setNull(index, Types.NULL);
} else {
stat.setObject(index, Json.toJson(obj, JsonFormat.tidy()), Types.OTHER);
}
}
示例6: cast
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public String cast(Object src, Class<?> toType, String... args)
throws FailToCastObjectException {
for (Method method : Mirror.me(src).getMethods()) {
if ("toString".equals(method.getName())) {
return src.toString();
}
}
return Json.toJson(src, JsonFormat.tidy());
}
示例7: cast
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public String cast(Object src, Class<?> toType, String... args)
throws FailToCastObjectException {
if (null != src && CharSequence.class.isAssignableFrom(src.getClass().getComponentType())) {
return Lang.concat(",", (CharSequence[]) src).toString();
}
return Json.toJson(src, JsonFormat.compact());
}
示例8: createMenu
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public boolean createMenu(Menu... menu) {
String url = mergeCgiBinUrl(createMenuURL + getAccessToken());
Map<String, Object> body = new HashMap<String, Object>();
body.put("button", menu);
String data = Json.toJson(body, JsonFormat.compact());
APIResult ar = wechatServerResponse(url,
HTTP_POST,
data,
"生成公众号[%s]的自定义菜单失败.");
return ar.isSuccess();
}
示例9: batchMove2Group
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public boolean batchMove2Group(Collection<String> openIds, int groupId) {
String url = mergeCgiBinUrl(updateMembersGroupURL + getAccessToken());
Map<String, Object> data = new HashMap<String, Object>();
data.put("openid_list", Json.toJson(openIds));
data.put("to_groupid", groupId);
APIResult ar = wechatServerResponse(url,
HTTP_GET,
Json.toJson(data, JsonFormat.compact()),
"批量移动公众号[%s]的%d个用户到新分组[%d]失败.",
openIds.size(),
groupId);
return ar.isSuccess();
}
示例10: createQR
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public QRTicket createQR(Object sceneId, int expireSeconds) {
String url = mergeCgiBinUrl(createQRCodeURL + getAccessToken());
NutMap data = new NutMap();
NutMap scene;
// 临时二维码
if (expireSeconds > 0) {
data.put("action_name", "QR_SCENE");
data.put("expire_seconds", expireSeconds);
scene = Lang.map("scene_id", Castors.me().castTo(sceneId, Integer.class));
}
// 永久二维码
else if (sceneId instanceof Number) {
data.put("action_name", "QR_LIMIT_SCENE");
scene = Lang.map("scene_id", Castors.me().castTo(sceneId, Integer.class));
}
// 永久字符串二维码
else {
data.put("action_name", "QR_LIMIT_STR_SCENE");
scene = Lang.map("scene_str", sceneId.toString());
}
data.put("action_info", Lang.map("scene", scene));
APIResult ar = wechatServerResponse(url,
HTTP_POST,
Json.toJson(data, JsonFormat.compact()),
"创建公众号[%s]的[%s]场景二维码失败.");
return Json.fromJson(QRTicket.class, Json.toJson(ar.getContent()));
}
示例11: getFollowers
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public List<Follower> getFollowers(Collection<Follower2> users) {
String url = mergeCgiBinUrl(batchUserInfoURL + getAccessToken());
String data = Json.toJson(Lang.map("user_list", users), JsonFormat.compact());
APIResult ar = wechatServerResponse(url,
HTTP_POST,
data,
"批量获取公众号[%s]的%d个用户信息失败.",
users.size());
return Json.fromJsonAsList(Follower.class, Json.toJson(ar.get("user_info_list")));
}
示例12: testGetMenu
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Test
public void testGetMenu() {
log.info("====== MenuAPI#getMenu ======");
String mockup_menus = "{\"menu\":{\"button\":"+Json.toJson(customerMenus,JsonFormat.compact())+"}}";
MockUpHttpGet(mockup_menus);
List<Menu> menus = wechatAPI.getMenu();
assertNotNull(menus);
assertEquals(menus.size(), 3);
}
示例13: end
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public void end(Object ctx) {
try {
if (Mvcs.getReq().getRequestURI().endsWith(".json")) {
Mvcs.write((HttpServletResponse)ctx, list, JsonFormat.compact());
} else {
Writer writer = ((HttpServletResponse)ctx).getWriter();
for (NutMap map : list) {
writer.write(String.format("%s,%s\n", map.get("ok"), map.get("msg")));
}
}
} catch (IOException e) {
e.printStackTrace();//不常见
}
}
示例14: save
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public void save(String token, int time, long lastCacheTimeMillis) {
at = new WxAccessToken();
at.setToken(token);
at.setExpires(time);
at.setLastCacheTimeMillis(lastCacheTimeMillis);
log.debugf("new wx access token generated : \n %s", Json.toJson(at, JsonFormat.nice()));
}
示例15: get
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public WxAccessToken get() {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
if (tokenKey == null) {
throw new RuntimeException("Redis token key should not be null!");
}
Map<String, String> hash = jedis.hgetAll(tokenKey);
if (Lang.isEmpty(hash)) {
log.warnf("could not find a valid token in redis with key [%s]", tokenKey);
return null;
}
WxAccessToken at = new WxAccessToken();// 从redis中拿出3个值组装成WxAccessToken返回
at.setToken(hash.get("token"));
at.setLastCacheTimeMillis(Long.valueOf(hash.get("lastCacheMillis")));
at.setExpires(Integer.valueOf(hash.get("expires")));
log.debugf("wx access_token fetched from redis with the key [%s] : \n %s",
tokenKey,
Json.toJson(at, JsonFormat.nice()));
return at;
}
catch (Exception e) {
e.printStackTrace();
}
finally {
// jedisPool.returnResource(jedis); //这是老版本归还连接的方法 已经deprecated
jedis.close();// 2.9.0的方法直接close
}
return null;
}