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

相关文章:

  • 2022-01-16
  • 2021-06-06
  • 2021-05-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案