/**
*
* @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":"字符串" 转换之前之后对比