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
In our web application, we have a use case to transform all value from long to string when its key is found in a given key set. Currently, this was implemented as a ring middleware prior to serialization. It walks through the ring body then do the transformation. However, this operation eats quite lot of CPU time and quickly becomes the bottleneck of our application.
To optimize this behaviour, I hacked cheshire's generate-map function to add a hook on the value. At the moment, there is no way to extend the default behaviour, so I have to reimplement generate-map/generate-array and generate in cheshire.generate to make it work.
There is key-fn option to transform keyword key in object. A further step can be adding key-value-fn that transforms the value with both key and value provided as context.
If this idea makes sense to you, I would like to create a pull request for this.
The text was updated successfully, but these errors were encountered:
I think it's useful, but I'm hesitant to include it because of the scope creep that it adds to Cheshire. I'm concerned that we essentially do the work of a general purpose map transformation function library.
I'm not sure how to reconcile that, I'd be interested if there were any other folks who wanted to weigh in with their opinion on it.
@dakrone Thank you for your response. I can understand your concern. The reason I want to do it within cheshire is mostly about performance. Since cheshire has to walk through the data structure in order to serialize it, it's the ideal phase to do it.
From another perspective, this key-value-fn is a little bit like @JsonSerialize annotation of jackson which could customize serializer on a field level.
In our web application, we have a use case to transform all value from long to string when its key is found in a given key set. Currently, this was implemented as a ring middleware prior to serialization. It walks through the ring body then do the transformation. However, this operation eats quite lot of CPU time and quickly becomes the bottleneck of our application.
To optimize this behaviour, I hacked cheshire's
generate-map
function to add a hook on the value. At the moment, there is no way to extend the default behaviour, so I have to reimplementgenerate-map
/generate-array
andgenerate
incheshire.generate
to make it work.There is
key-fn
option to transform keyword key in object. A further step can be addingkey-value-fn
that transforms the value with both key and value provided as context.If this idea makes sense to you, I would like to create a pull request for this.
The text was updated successfully, but these errors were encountered: