本文整理汇总了Java中org.nutz.json.JsonFormat类的典型用法代码示例。如果您正苦于以下问题:Java JsonFormat类的具体用法?Java JsonFormat怎么用?Java JsonFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonFormat类属于org.nutz.json包,在下文中一共展示了JsonFormat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:29,代码来源:EntityHolder.java
示例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);
}
}
});
}
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:19,代码来源:WxHistoryService.java
示例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());
}
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:23,代码来源:IotExchangeModule.java
示例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);
}
开发者ID:javamonkey,项目名称:beetl2.0,代码行数:27,代码来源:NutJsonFunction.java
示例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);
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:8,代码来源:PsqlJsonAdaptor.java
示例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());
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:11,代码来源:Object2String.java
示例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());
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:9,代码来源:Array2String.java
示例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();
}
开发者ID:elkan1788,项目名称:mpsdk4j,代码行数:13,代码来源:WechatAPIImpl.java
示例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();
}
开发者ID:elkan1788,项目名称:mpsdk4j,代码行数:15,代码来源:WechatAPIImpl.java
示例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()));
}
开发者ID:elkan1788,项目名称:mpsdk4j,代码行数:30,代码来源:WechatAPIImpl.java
示例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")));
}
开发者ID:elkan1788,项目名称:mpsdk4j,代码行数:12,代码来源:WechatAPIImpl.java
示例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);
}
开发者ID:elkan1788,项目名称:mpsdk4j,代码行数:12,代码来源:MenuAPITest.java
示例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();//不常见
}
}
开发者ID:wendal,项目名称:whale,代码行数:15,代码来源:IotHttpCmdHandler.java
示例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()));
}
开发者ID:nutzam,项目名称:nutzwx,代码行数:9,代码来源:MemoryAccessTokenStore.java
示例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;
}
开发者ID:nutzam,项目名称:nutzwx,代码行数:32,代码来源:RedisAccessTokenStore.java
示例16: add_video
import org.nutz.json.JsonFormat; //导入依赖的package包/类
@Override
public WxResp add_video(File f, String title, String introduction) {
if (f == null)
throw new NullPointerException("meida file is NULL");
String url = String.format("https://api.weixin.qq.com/cgi-bin/material/add_material?type=video&access_token=%s", getAccessToken());
Request req = Request.create(url, METHOD.POST);
req.getParams().put("media", f);
req.getParams().put("description",
Json.toJson(new NutMap().setv("title", title).setv("introduction", introduction),
JsonFormat.compact().setQuoteName(true)));
Response resp = new FilePostSender(req).send();
if (!resp.isOK())
throw new IllegalStateException("add_material, resp code=" + resp.getStatus());
return Json.fromJson(WxResp.class, resp.getReader("UTF-8"));
}
开发者ID:nutzam,项目名称:nutzwx,代码行数:16,代码来源:WxApi2Impl.java
示例17: toString
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public String toString() {
boolean attMap = attrs.getInnerMap().isEmpty();
return String.format("%s:%s:%s:\"%s\"",
Strings.dup("> ", depth),
type,
attMap ? ""
: Json.toJson(attrs.getInnerMap(),
JsonFormat.compact()
.setQuoteName(false)),
text());
}
开发者ID:zozoh,项目名称:zdoc,代码行数:12,代码来源:ZDocNode.java
示例18: toString
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public String toString() {
return String.format("/*%s*/%s", super.toString(), Json.toJson(this, JsonFormat.compact()));
}
开发者ID:strictnerd,项目名称:windows-file-change,代码行数:4,代码来源:BasePojo.java
示例19: getFormat
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public JsonFormat getFormat() {
return format;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:4,代码来源:JsonRenderImpl.java
示例20: setFormat
import org.nutz.json.JsonFormat; //导入依赖的package包/类
public void setFormat(JsonFormat format) {
this.format = format;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:4,代码来源:JsonRenderImpl.java
注:本文中的org.nutz.json.JsonFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论