Recursive mapEntries()
#329
Replies: 2 comments
-
I think it's best if we gather more use cases first. In your case, the implementation wouldn't need circular reference detection, since database results typically don't include circular references, whereas a general solution would need that detection. Re-casing keys from database results is typically a performance-sensitive task, since database retrieval is commonly a hot path of SaaS APIS, for example. Therefore, you wouldn't want to waste CPU cycles on circular reference detection and the general solution would be less than ideal. There's also a question of how to handle arrays and
If we do add such a thing, I'd suggest the following behavior:
|
Beta Was this translation helpful? Give feedback.
-
I totally agree :thumbs_up: .
Actually I get JSON from my backend, so I didn’t even think of any other possibilities :-) .
Суббота, 21 декабря 2024, 18:03 +03:00 от Alec Larson ***@***.***>:
I think it's best if we gather more use cases first.
In your case, the implementation wouldn't need circular reference detection, since database results typically don't include circular references, whereas a general solution would need that detection. Re-casing keys from database results is typically a performance-sensitive task, since database retrieval is commonly a hot path of SaaS APIS, for example. Therefore, you wouldn't want to waste CPU cycles on circular reference detection and the general solution would be less than ideal.
There's also a question of how to handle arrays and Map objects.
* Do array indices get mapped by the callback, or are they only recursed in search of plain objects? In my opinion, it should be the latter, but some use cases may prefer the former.
* Same question for Map objects. In your case, it'd be best performance-wise to not have any Map handling, since database retrieval never returns them.
If we do add such a thing, I'd suggest the following behavior:
* Assume JSON data only (no Map or Set objects)
* The callback only maps key-value pairs of plain objects
* Arrays are recursed, but only copied if a plain object is found within
* No support for circular references
—
Reply to this email directly, view it on GitHub , or unsubscribe .
You are receiving this because you authored the thread. Message ID: <radashi-org/radashi/repo-discussions/329/comments/11637916 @ github . com>
|
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I need to map snake case keys to camel case in objects I get from a backend. As far as I understand,
mapEntries()
doesn't go deep into nested values. I implemented this functionality, so I wanted to ask whether it's worth making a PR.Thanks.
Beta Was this translation helpful? Give feedback.
All reactions