MongoDB “NumberLong/$numberLong” issue while converting back to Java Object

I am having a json which is somethink like {"Header" : {"name" : "TestData", "contactNumber" : 8019071740}}

If i insert this to mongoDB it will be something like

{"_id" : ObjectId("58b7e55097989619e4ddb0bb"),"Header" : {"name" : "TestData","contactNumber" : NumberLong(8019071743)}

When i read this data back and try to convert to java object using Gson it throws exception

List<String> dataList = new ArrayList();
MongoIterable mongoIterable = 
collection.find(BasicDBObject.parse(queryCond)).projection(BasicDBObject.parse(filterStr)).sort(orderBy).skip((currentPageValue-1)*pageCountValue).limit(pageCountValue);

 MongoCursor<Document> mongoCursor = mongoIterable.iterator();
 Gson gson = new Gson();
  while(mongoCursor.hasNext()){
        Document document= mongoCursor.next();
        dataList.add(gson.toJson(document));
  }

 

Guess you like

Origin blog.csdn.net/zhuchunyan_aijia/article/details/116308245