问题描述
我愿意将代码从mongojack迁移到支持新的异步mongo驱动程序的东西.但是我发现编码/解码的新方法是通过Codec
进行的,而且我看不到自己为模型中的每个类都编写了Codec
.这就是为什么我宁愿编写一个给定一个类创建一个Codec
的库的原因.但是我不知道怎么做,也不知道是否已经有一些努力去实现相同的目标.是否有一些实现我想要的功能的库?如果没有,实现它的最佳方法是什么.
I'm willing to migrate my code from mongojack to something that supports the new async mongo driver. Yet I find that the new way of encoding/decoding is through Codec
s and I don't see myself writing a Codec
for every class in my model. That's why I'd rather write a lib that given a class creates a Codec
. However I don't know how, nor do I know if there's already some effort out there trying to achieve the same.Are there some libs that achieve what I want? if not, what's the best approach to achieve it.
(我知道我可能应该在其中的某个地方使用CodecProvider
,但我仍然不知道从哪里开始)
(I know I should probably use CodecProvider
somewhere in there, but I still don't know where to start)
推荐答案
是的,如果您使用Jackson,则可以使用 https://github.com/ylemoigne/mongo-jackson-codec ,它将为您自动处理.
Yes, if you use Jackson you can use the mongo-jackson-codec from https://github.com/ylemoigne/mongo-jackson-codec which will handle it automatically for you.
这篇关于有什么方法可以自动创建Mongo编解码器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!