Code Monkey home page Code Monkey logo

Comments (2)

cowtowncoder avatar cowtowncoder commented on September 5, 2024

I guess the first thing would be to understand why you think alternate handling is needed: why doesn't method itsel fail if you want to throw an exception? What is the problem in serializing it as null that you are trying to solve?
Or if you do not want to serialize such value at all, JsonInclude.NON_ABSENT (or just NON_EMPTY which cover case of absent) can be used to configure behavior.

Beyond this it could perhaps be possible to allow alternate configuration of default Optional serializer this module provides, and then allowing passing differently configured instance.
But I want to first understand the problem to solve, before considering solutions.

from jackson-modules-java8.

dinhani avatar dinhani commented on September 5, 2024

You are right.

Actually I changed my code to this and dropped the Optional.

return queryUser.execute(id).orElseThrow(HttpStatusException.notFound());

My intention was not only for this use case, but also for other use cases where the developer might want to return something else, like a default value or dummy object instead of null.

But after thinking more deeply, I think all these use cases can be handled by the application code with custom getters when serializing the object and should not be responsibility of the library.

from jackson-modules-java8.

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.