Giter VIP home page Giter VIP logo

Comments (2)

joelittlejohn avatar joelittlejohn commented on May 11, 2024

From [email protected] on May 07, 2012 22:19:27
The only time I have used union types is to allow null for a field. Note that the schema calls out this use case specifically in section 5.1 :
" null Value MUST be null. Note this is mainly for purpose of
being able use union types to define nullability. If this type
is not included in a union, null values are not allowed (the
primitives listed above do not allow nulls on their own)."

A lot of the types for my fields look like: {"type": ["string","null"]}
I only speak from my experience so I don't know how commonly used this is but it should be simple to add a special case for it. It would work seamlessly as long as boxed types are being used.

from jsonschema2pojo.

joelittlejohn avatar joelittlejohn commented on May 11, 2024

From [email protected] on May 08, 2012 21:55:44
This issue has been around for a while and I'm now leaning away from the 3rd option described above. It would be nice to have a simple implementation for now that doesn't impose any additional requirements on the json (like extra 'type' properties).

I've fixed this as per Option 1: if an array is encountered (a union type) just use the first type in the array. Maybe a more sophisticated handling of union types could be applied to a later version, but in general if you want to do data-binding to a statically typed language like Java it's best to avoid such constructs.

This should satisfy your use-case Patrick, just make sure the "null" type comes last.

from jsonschema2pojo.

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.