简体   繁体   English

无需使用注释即可自定义序列化策略spring-data-mongodb

[英]Customization of serialization policy spring-data-mongodb without using annotations

I want to customize / configure the serialization policy of spring-data-mongodb (version 1.1.1.RELEASE) without using annotations (like @Id, @Document, @Field) because I do not have access to the domain classes. 我想自定义/配置spring-data-mongodb(版本1.1.1.RELEASE)的序列化策略, 而不使用注释(如@ Id,@ Document,@ Field),因为我无法访问域类。

Is this possible? 这可能吗? If yes, what is the most efficient way to do this? 如果是,那么最有效的方法是什么?

据我所知,为了自定义类序列化,你唯一能做的就是为每个类定义自定义转换器,这在参考文献中有描述。

Keep in mind to have a Read- and a WriteConverter for each of your domain classes. 请记住,为每个域类创建一个Read-和WriteConverter。 Missing the WriteConverter might lead to unexpected content in MongoDB which is not readable by your custom ReadConverter. 缺少WriteConverter可能会导致MongoDB中出现意外内容,而自定义ReadConverter无法读取该内容。

ReadConverter should be annotated with @ReadingConverter and WriteConverter should be annotated with @WritingConverter . ReadConverter应使用@ReadingConverter进行注释,WriteConverter应使用@WritingConverter进行注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM