gson转换带有objectId的问题
/**
*
* @Description: objectid 转换成string 不然就会objectid对象序列化了
* @param @param obj
* @param @return
* @return String
* @throws
* @author liangbo
* @date 2016-5-13
*/
public static String parseJsonSetId(Object obj) {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(ObjectId.class,
new JsonSerializer<ObjectId>() { @Override
public JsonElement serialize(ObjectId arg0, Type arg1,
JsonSerializationContext arg2) {
return new JsonPrimitive(arg0.toString());
}
});
Gson gson = builder.create();
return gson.toJson(obj);
}
"_id":{"_time": ,"_machine":,"_inc":,"_new":} "_id":"字符串" 转换之前之后对比
gson转换带有objectId的问题的更多相关文章
- hibernate结合使用gson转换json中一点看法
转发请注明出处:http://www.cnblogs.com/shizhongtao/p/3680216.html 在前后台的交互中,经常需要把bean对象与xml或者json,这里就把自己以前遇到的 ...
- json(gson) 转换html标签带来的麻烦
gson 转换html标题时,会把html(特殊字符转换为unicode编码) ,所以为了避免这个问题GsonBuilder类 有一个 disablehtmlEscaping方法. 就可以让gson类 ...
- Gson转换时,Double转式化
package com.mall.core; import java.lang.reflect.Type; import java.text.DecimalFormat; import com.goo ...
- Gson转换复杂对象报错【类型强转错误】
一.问题: 项目里遇到一个需求,规则文件下载后,导入本地解析. 采用的方案是:获取复杂对象,使用谷歌Gson转换为字串保存为文件下载,客户端读取文件,解析字串,反解对象 遇到的问题:传输的对象是一个嵌 ...
- GSON转换日期数据为特定的JSON数据
通过JSON传递数据的时候经常需要传递日期,Java中可以通过GSON将日期转换为特定格式的JSON数据. 1.普通的GSON转换日期 public void query(HttpServletReq ...
- gson转换问题
list集合中integer问题 List<Integer> lists= gson.fromJson(params.get("lists"), new TypeTok ...
- [转]使用 google gson 转换Timestamp或Date类型为JSON字符串.
创建类型适配类: import java.lang.reflect.Type; import java.sql.Timestamp; import java.text.DateFormat; impo ...
- 使用 google gson 转换Timestamp或Date类型为JSON字符串.
http://blog.csdn.net/z69183787/article/details/13016289 创建类型适配类: import java.lang.reflect.Type; impo ...
- Gson转换json数据为对象
可以通过Gson使用两种方法,将json字符串转换为对象,以下面该段报文做测试 { "id": 84041462, "lastName": "小华&q ...
随机推荐
- NeHe OpenGL教程 第二十二课:凹凸映射
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- WindowsForm通过字符串名称实例化控件
private Control FindControl(Control control, string controlName) { Control c1; foreach (Control c in ...
- ICANN认证企业列表
查询地址: http://www.internic.net/alpha.html
- 转-Activity中使用orientation属性讲解及需注意的问题
http://www.software8.co/wzjs/yidongkaifa/6504.html 今天遇到了一个关于orientation的问题查了点资料记录一下,只有点点滴滴的积累,才能让我们更 ...
- 最大公约数Greatest Common Divisor(GCD)
一 暴力枚举法 原理:试图寻找一个合适的整数i,看看这个整数能否被两个整形参数numberA和numberB同时整除.这个整数i从2开始循环累加,一直累加到numberA和numberB中较小参数的一 ...
- SQL Server 2005 不允许远程连接解决方法
刚刚安装的数据库系统,按照默认安装的话,很可能在进行远程连接时报错,通常是错误:“在连接到 SQL Server 2005 时,在默认的设 置下 SQL Server 不允许进行远程连接可能会导致此失 ...
- codeblocks调试快捷键说明
使用codeblocks避免不了快捷键: 在调试程序的时候: 首先在view->toolbar->debugger调出来:快捷方式可以自己看 RUN to Cursor :F4 单步调试 ...
- springmvc 对REST风格的支持
1.PathVariable注解 用于映射url的占位符到目标方法的参数中 例子: @RequestMapping("/testPathVariable/{id}") public ...
- 我自己做的网站终于上线啦,用tornado做的,求围观 www.yustock.live
跟股票相关的一个小网站~ www.yustock.live
- C Primer Plus(第五版)2
在本章中你将学习下列内容------------------------------------------------------------------1.运算符:= 2.函数:main(),pr ...