Comments (2)
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.
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)
- json schema $ref request address contains separator (':') , NTFS ADS separator (':') in file name is forbidden. HOT 1
- Generated output stays empty HOT 1
- Map generation from standard JsonSchema HOT 2
- Duplicate constructors generated when all properties are required; and both includeAllPropertiesConstructor and includeRequiredPropertiesConstructor are true
- Maven Plugin: inconsistent logging of ClassAlreadyExistsException HOT 1
- Hide sensitive properties from toString() HOT 1
- Question re default keyword on objects
- Different classes are generated for the same named attribute at a different JSONPath location HOT 2
- Json file has JSONObject called Data, but library is generating a Java class called Datum instead of Data. HOT 1
- Generating same class that appears few times in the JSON file HOT 3
- Mirror "deprecated" annotation from JSON schema in the generated code
- Comparison method is created for each array type declared in JSON sample file HOT 2
- Generating constructors using JSON file HOT 13
- Generation failure after upgrade HOT 4
- When is the next release?
- SnakeYAML 1.3.3 vulnerability - upgrade dependency to v2.0 or superior HOT 2
- there are still 2 javax.annotation imports in my generated code after using useJakartaValidation HOT 1
- Trying to make Custom annotations work (unsuccessfully) using jsonschema2pojo directly from code (embedded) using jsonschema2pojo-core. Is that doable? HOT 2
- [Wiki] [Broken-Link] Link to address.schema.json is busted
- Wiki Reference page broken? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonschema2pojo.