You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Preserve types transformation is provided by RES and its job is to restore original types for event data and metadata. When data and metadata are hashes (the most common case), registered types will be restored according to their configuration. This means, in particular, that data keys will be symbolized if they were originally symbols and if config for `Symbol` was registered for `PreserveTypes` transformation.
151
+
152
+
Let's set up `PreserveTypes` with the same types config that is used by `RailsEventStore::JSONClient` default mapper:
Now we can use it in the transformation pipeline as shown above.
207
+
208
+
There's one more thing - `PreserveTypes` uses event metadata to store information about what needs to be transformed and how, something like this:
209
+
210
+
```ruby
211
+
"types": {
212
+
"data": {
213
+
"order_id": ["Symbol", "String"],
214
+
"refund_id": ["Symbol", "String"]
215
+
}
216
+
}
217
+
```
218
+
219
+
this will result in data keys with these names being restored from String to Symbols.
220
+
221
+
Why does this matter in our case? Because old events were stored with `refund_id` data key, so `PreserveTypes` has to run before our custom `RefundToReturnEventMapper`. Otherwise it won't be able to symbolize `return_id` key because there's no corresponding type data in the event's metadata.
222
+
147
223
### Other considerations
148
224
149
225
1. We use load-time transformation only: load() transforms when reading, dump() preserves original format
0 commit comments