简体   繁体   English

如何自定义Salat中没有注释的序列化行为?

[英]How to customize serialization behavior without annotations in Salat?

I'm using Salat library to serialize objects to be stored in MongoDb via Casbah. 我正在使用Salat库来序列化要通过Casbah存储在MongoDb中的对象。 Sometimes I need to tune little bit how fields will be serialized, and Salat's Annotations is a pretty convenient way to do it. 有时我需要调整字段的序列化方式,而Salat的注释是一种非常方便的方法。

BUT, Is there any way to describe serialization parameters(Key, Ignore etc) not directly in case-classes(models) via Annotations, but in some external point, to keep my models clear from Salat dependency(aka POJO/POCO)? 但是,是否有任何方法不是通过注释直接在案例类(模型)中描述序列化参数(键,忽略等),而是在某些外部方面使我的模型摆脱了Salat依赖性(又名POJO / POCO)?

Yes, you can add custom serialization logic to your Salat context. 是的,您可以将自定义序列化逻辑添加到Salat上下文中。

Example from Salat unit tests: Salat单元测试的示例:

WibbleTransformer WibbleTransformer

Custom context with custom transformers added 添加了自定义转换器的自定义上下文

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

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