Code Monkey home page Code Monkey logo

Comments (8)

k163377 avatar k163377 commented on August 22, 2024 1

I am positively considering adding this feature.
I have made a prototype at kogera for policy consideration.
ProjectMapK/jackson-module-kogera#224

It will be basically the same usability as deserialization of value class.
The difference is that the wrapped type is also deserialized by the context-accessible KeyDeserializer.

However, I am busy and sick, so it may take some time until I can merge it into kotlin-module.
I hope to complete it by May at the latest.


@cowtowncoder
I have two questions about Jackson functionality.

I don't believe there is a JsonCreator like feature used to deserialize keys, is this correct?

Also, are there any caveats about searching for another KeyDeserializer from a KeyDeserializer?
https://github.com/ProjectMapK/jackson-module-kogera/pull/224/files#diff-b03a6f91081da3aa22c53b161b0a2f6f1a0cf4ba318329907046b5f5335b17c8R72-R73

I am assuming that this is a very limited edge case, but I am assuming that there are nested types that require a special deserialization method.
https://github.com/ProjectMapK/jackson-module-kogera/pull/224/files#diff-11c6e0b61e487e3914690655846ffd6100b92c022082ea610bb8d086f7be18dcR87-R116

from jackson-module-kotlin.

k163377 avatar k163377 commented on August 22, 2024 1

@junkdog
A generic key deserializer for the value class is not currently provided by jackosn-module-kotlin.
This means that Cannot find a (Map) Key deserializer should be thrown as for other classes.

It is still possible to deserialize a value class as a Map key by registering the appropriate key deserializer.

For these reasons, I interpret this as a feature request.

from jackson-module-kotlin.

junkdog avatar junkdog commented on August 22, 2024

Just to clarify, previous versions of jackson don't exhibit errors when using value classes as keys in maps. As such, I think this should be labeled as a bug and not an enhancement.

from jackson-module-kotlin.

cowtowncoder avatar cowtowncoder commented on August 22, 2024

Maybe the difference here is wrt serialization (where "value.toString()" is used for "unknown" types) vs deserialization (where exception will be thrown)?
Handling differs quite a bit b/w reading (deser) and writing (ser).

from jackson-module-kotlin.

cowtowncoder avatar cowtowncoder commented on August 22, 2024

@cowtowncoder I have two questions about Jackson functionality.

I don't believe there is a JsonCreator like feature used to deserialize keys, is this correct?

No I don't think so; except for @JsonKey annotation... use of which might work via custom AnnotationIntrospector.

Also, are there any caveats about searching for another KeyDeserializer from a KeyDeserializer? https://github.com/ProjectMapK/jackson-module-kogera/pull/224/files#diff-b03a6f91081da3aa22c53b161b0a2f6f1a0cf4ba318329907046b5f5335b17c8R72-R73

Not sure; in general ideally would be resolved earlier and not during reading (in fact, it really should be done during construction/resolution for deserialization; sometimes not doable for serialization). But other than that I suspect it should be fine.

from jackson-module-kotlin.

k163377 avatar k163377 commented on August 22, 2024

except for @jsonkey annotation... use of which might work via custom AnnotationIntrospector.

Is this not a function for @JsonValue?
I wanted to make sure there is no such thing as @JsonKeyCreator.

from jackson-module-kotlin.

k163377 avatar k163377 commented on August 22, 2024

I will not implement this feature in kotlin-module until the following issues are resolved, as it will override custom implementations defined by the user.
FasterXML/jackson-databind#4444

I am unable to work on a fix as my busy state has become rather worse.
If anyone has a strong desire for this feature, I would appreciate it if you could fix it.

from jackson-module-kotlin.

cowtowncoder avatar cowtowncoder commented on August 22, 2024

Is this not a function for @JsonValue?
I wanted to make sure there is no such thing as @JsonKeyCreator

No, as name implies, it is for JSON values -- keys are specifically separate thing (from Jackson perspective), key names for java.util.Maps bound from JSON Object property names (vs property values). Part of the problem is that Property names are exposed as JsonToken.FIELD_NAME so regular value JsonDeserializer cannot be used; and thereby there is separate KeyDeserializer.
At any rate, handling is quite separate and as such I don't see how @JsonValue could be used outside limited cases (like with maybe Enum type)

But there are also other relevant annotations: @JsonDeserialize(keyUsing = <KeyDeserializer class> and @JsonSerialize(keyUsing = <key serializer class> that can be used on class to mark handler(s).

from jackson-module-kotlin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.