Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Mongo convert to document from json string

I have a Mongo collection annotated with @Document and I want the possibility to also get that Java object from a String (JSON) as we're getting these classes pushed into a queue as String.

Is there a method in Spring-Data-Mongo which converts from JSON to the actual Document object?

like image 880
ianaz Avatar asked Dec 05 '25 04:12

ianaz


1 Answers

@Autowired
MongoTemplate mongoTemplate;

and then

mongoTemplate.getConverter().read(MatchMongo.class, (DBObject) JSON.parse(json));

Thanks to freakman, your answer helped a lot

like image 146
ianaz Avatar answered Dec 08 '25 04:12

ianaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!