Support UUID and other stringlike types as keys#435
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #435 +/- ##
=======================================
Coverage 90.26% 90.26%
=======================================
Files 7 7
Lines 1366 1366
=======================================
Hits 1233 1233
Misses 133 133 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@quinnj gentle ping in case you missed notification |
|
@quinnj ping |
| StructUtils.lowerkey(::JSONStyle, s::AbstractString) = s | ||
| StructUtils.lowerkey(::JSONStyle, sym::Symbol) = String(sym) | ||
| StructUtils.lowerkey(::JSONStyle, n::Union{Integer, Union{Float16, Float32, Float64}}) = string(n) | ||
| StructUtils.lowerkey(::JSONStyle, s::Union{StringLike, Real}) = string(s) |
There was a problem hiding this comment.
hmmmm, changing this to Real makes me a bit more nervous, just because now we're widening to a lot more types; can we keep this conservative and do:
| StructUtils.lowerkey(::JSONStyle, s::Union{StringLike, Real}) = string(s) | |
| StructUtils.lowerkey(::JSONStyle, s::Union{StringLike, Integer, Float16, Float32, Float64}) = string(s) |
There was a problem hiding this comment.
I don't see an issue with widening. I think it is expected for custom numbers to serialize the same way as builtin ones, and a reasonable default behavior. Don't we want to work out of the box for as many types as possible? Abstract types in Base are defined specifically so that a user can get as much behavior as he can, for free, by just inheriting from them. So, why instead of supporting that we want to give a user MethodError?
quinnj
left a comment
There was a problem hiding this comment.
Sorry for the slow review; looks great! I had one request, but then I say we merge.
This PR fixes the following error with UUID and other types:
The same error happens with Char, VersionNumber and some other types which should work out of the box.
For
lowerkeyI also changedUnion{Float16, Float32, Float64}toReal, but if there is a reason why only specific types were supported we can revert it.