-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider supporting map key types that are value-type String wrappers #577
Comments
So just to confirm I understand this: it'd be good to have special handling for Value types that consists of a single I won't be able to help on Kotlin side (since I don't know Kotlin that well) but I hope someone else might want to tackle this, via added |
Yes thats what I meant. Possibly also Data Classes with a single Value classes can be used as a way to add type safety without overhead. Instead of a String arg, define a value class and now you cannot put the customer number where the order number is supposed to go. On the JVM level this should impose no additional allocations or indirections. Kotlin also has type aliases, but those do not add type safety as they are assignment-compatible with their aliases, and thus they already work with Jackson. If you point me in the right direction I might be able to help with the Kotlin side. |
I hope module maintainers can help here, unfortunately I don't really know the codebase. |
Deserializing a map where the key is an value class does not work in 2.17 unfortunately: import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
@JvmInline
value class Id(val value: Int)
data class Foo(val valuesById: Map<Id, String>)
val objectMapper = jacksonObjectMapper()
val serialized = objectMapper.writeValueAsString(Foo(mapOf(Id(1) to "one", Id(2) to "two")))
val deserialized = objectMapper.readValue(serialized, Foo::class.java) Throws:
|
@geirsagberg If there are issues remaining, please file a new issue outlining specific problem. It may (and probably should) reference this issue as background, but we do not typically re-open old issues unless it's part of on-going development of feature for branch from which there is no release yet. |
Got it, I have opened issue #777. |
It would be nice to have support for stringly-typed values, such as
@JvmInline value class SKU(val value: String)
. Writing custom map key deserializers for every custom Kotlin value type that is really just a String doesn't seem ergonomic.Currently this throws a
java.lang.IllegalArgumentException: Cannot find a (Map) Key deserializer for type [simple type, class ValueTypeTest$SKU]
, repro case:The text was updated successfully, but these errors were encountered: