I am new to Lucee and the first task was migrating a CF10 legacy app. One property of that app was to produce JSON with lowercase keys.
See this discussion for more detail and the way I solved it if you are interested: Topic 10619
As a result of trying to solve the issue I thought I could offer this proposal for the SerializeJSON function. The idea is that if you need something custom you can do it on a case-by-case basis.
-
Optional parameter: keyCase: ‘preserve’ | ‘upper’ | ‘lower’
If missing, revert to the server settings as now: preserve or upper -
Optional parameter: transform(key, value) function
The idea is for those edge cases where you need complete control on a specific serialization task so you can adjust each key:value result as you go.
eg you might need transforms like the ones GSON offers:
LOWER_CASE_WITH_UNDERSCORES, LOWER_CASE_WITH_DASHES, etc
but with a transform function you could do whatever you liked, and even just filter for a specific key that needs adjustment to either the key name or value.
BTW: as part of my attempts to solve the issue at hand, I made a jar class wrapper around GSON and tried that instead since it has a method similar to the one I am proposing where I set all keys to lowercase. That was definitely fast, but not accurate. eg a numeric integer field from Lucee of 38 that SerializeJSON returns as “38”, GSON returned as “38.0”.
Opinion: I know you can manage the key casing and format when you create the structs in the first place. In my mind, however, the serialization is a concern that the originating code should not have to worry about. eg if you DID need lowercase keys with dashes or to adjust a specific property name just for serialization because the requesting client needs it that way, this should be the concern of the serializer, not the business logic.
Anyway, just a suggestion.
Thanks,
Murray