Code Monkey home page Code Monkey logo

Comments (6)

brettwooldridge avatar brettwooldridge commented on September 24, 2024

@kaqqao HikariJSON is not dead, but in deep hibernation. 😁 Having said that, I believe that jackson can do everything you are asking for above with respect to custom (de)serializers. Have you investigated it?

from hikarijson.

kaqqao avatar kaqqao commented on September 24, 2024

Jackson unfortunately can't handle this case, because it targets Java <8. Still, the author is open to this in the upcoming Jackson 3, so I'll attempt to contribute this extension.
I was just hoping to get more library authors interested :) Especially for the libraries that are already focused on Java 8.

from hikarijson.

brettwooldridge avatar brettwooldridge commented on September 24, 2024

@kaqqao I use jackson, and to me it still seems possible to create a custom deserializer that itself is Java 8 aware.

Pardon the Kotlin, but this is from some of my company's code:

var json: String = ""
      @JsonRawValue
      get() = field
      @JsonDeserialize(using = MyCustomDeserializer::class)
      set(value) {field = value}

... this could easily be annotated with a Java 8 type annotation such as:

@Base64
var json: String = ""
      @JsonRawValue
      get() = field
      @JsonDeserialize(using = Jsr308Deserializer::class)
      set(value) {field = value}

... where Jsr308Deserializer performs AnnotatedType reflection on the target, sees @Base64, and dispatches accordingly.

Have you tried it?

from hikarijson.

kaqqao avatar kaqqao commented on September 24, 2024

It is possible to recover annotations on fields/methods, yes, but TYPE_USE annotations are not preserved in Jackson's JavaType (class it uses to capture generic types etc). As a result, contextual types (as Jackson calls top-level types and generic type arguments) are not possible to (de)serialize in this way. E.g. you can not register a deserializer that will globally catch @Base64 annotated types. For a field of type List<@Base64 Thing> you could register a custom deserializer instance that knows how to deal with that specific field, and it would have to deal with the entire type (i.e. List<@Base64 Thing>), but you couldn't register it globally so that Jackson processes the List part normally and triggers the custom logic for @Base64 Thing only, for any field anywhere automatically. Additionally, you can't do mapper.readValue(json, mapper.getTypeFactory().construct(annotatedType), so top-level annotations are always lost. It's a bit hard to explain if you're not looking into Jackson's code at the same time. JsonDeserializer only has access to JavaType which does not contain annotations. This would need to be in the core classes, that's why a Java <8 compatible library can't support it.

I've already talked to the Jackson's author, he confirmed my understanding...

from hikarijson.

kaqqao avatar kaqqao commented on September 24, 2024

Btw, feel free to close the issue if you don't really want it open for a hibernating project or don't want the feature in general.

And thanks for the responses!

from hikarijson.

brettwooldridge avatar brettwooldridge commented on September 24, 2024

@kaqqao Thanks for the clarification. I get it. I'm familar with some of the jackson internals. I'll leave this open, as it sounds useful.

from hikarijson.

Related Issues (7)

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.