8

I am using Mongo driver for java 3.2.2 and trying to convert the bson document to valid java object. When I am using the below java code :

Document value = (Document)dataObject.get(VALUE);
Gson gson = new Gson();
CustomClasss classObject = gson.fromJson(value.toJson(),CustomClass.class);

I am getting the exception while conversion. This exception is due to date and long fields in the value document above. While converting I am getting the extra

$date and $numberlong

fields from

value.toJson()

Any suggestions how I can do this conversion.

Thanks in Advance,

Amandeep

Amandeep Singh
  • 3,754
  • 8
  • 51
  • 72
  • 1
    Consider posting your document and its toJson() – mtj Jul 20 '16 at 05:50
  • Thanks mtj : this is the tojson I am getting , you can see there is $date which violates it from conversion : { "id" : 50000302,"LAST_UPDATED" : { "$date" : 1370457000000 }, "CREATED" : { "$date" : 1370457000000 } } – Amandeep Singh Jul 20 '16 at 07:27
  • It looks like this was already answered at [http://stackoverflow.com/questions/35209839/converting-document-objects-in-mongodb-3-to-pojos](http://stackoverflow.com/questions/35209839/converting-document-objects-in-mongodb-3-to-pojos) – rhogue Sep 19 '16 at 14:10

0 Answers0