MongoDB文档作为JsonNode(Jackson库) [英] MongoDB document as a JsonNode (Jackson library)

查看:133
本文介绍了MongoDB文档作为JsonNode(Jackson库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用例-

  1. 在mongodb中存储JSON模式(动态的,随时间变化).
  2. 从文件中读取JSON对象,并根据架构对其进行验证 (在#1中)
  3. 我正在使用此 JSON验证器.
  4. 我需要从mongo db中读取模式并将其转换为JsonNode (杰克逊图书馆).
  1. Store a JSON schema (dynamic, changes over time) in mongodb.
  2. Read JSON objects from a file and validate them against the schema (in #1)
  3. I am using this JSON Validator.
  4. I need to read the schema from mongo db and convert it to JsonNode (Jackson library).

我正在使用Java.

任何人都可以让我知道如何将mongodb文档转换为JsonNode..我之所以需要它,是因为我正在使用的验证器(在上面的#3中提到)需要一个JsonNode来构造架构对象.

Can anyone let me know how to convert a mongodb document to JsonNode.. I need this because the validator I am using (mentioned in #3 above) needs a JsonNode to construct the schema object.

将DBObject转换为JSON字符串然后再将其转换为JsonNode是否是性能优良的明智选择?

Is it fine performance wise to convert DBObject to JSON string and then convert it to JsonNode?

推荐答案

为什么不直接从DBObject转到JsonNode? iirc,JsonNode只是一个类似于DBObject的地图.从一个转换到另一个(然后再转换)应该非常简单.

Why not go straight from DBObject to JsonNode? iirc, JsonNode is just a map like DBObject is. Converting from one to the other (and back) should be pretty straightforward.

这篇关于MongoDB文档作为JsonNode(Jackson库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆