-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow collections to be null by default #156
Comments
I think the problem here is that fields are initialized with an empty collections, so your generated field would look like: @JsonProperty("experiences")
private List<Experience> experiences = new ArrayList<Experience>(); The default values are very useful when interacting with these types as there is no need to initialize every collection. There's no way to disable this as present but I guess we could add a configuration option that would allow you to leave these field uninitialized. If the field value was Before doing this though I think you should consider carefully whether this validation rule is really worth adding. By leaving these field uninitialized you will force anyone using these types to a) initialize the collection manually before adding values b) do null checks every time they use any collection in the generated types. Would it not be better to simply treat an empty "experiences" array the same as if none had been provided? |
If we treat the empty arrays as the same as none then our Validator (JSR 303) complains that the array should at least have one Experience object which is right |
I'm suggesting that if you treat empty arrays the same as none, then you don't need I'm not sure why an empty experiences array should be seen as a semantic problem for anyone who uses the serialized version. Can you think of an example in which an empty array could/would be treated differently than an omitted array? I don't see a printed empty array as a problem. If you really need to avoid printing these you could implement your own annotator that extends one of the existing annotators but adds |
Well removing "minItems" : 1 looks to be required at the moment. In the schema if I add "default" : null will it declare List experiences = null or by default all objects are created as Empty Lists ? |
Did you try it? Unfortunately I think that no, the logic is such that |
Yeah I tried it but does not work |
So you added the enhancement. Great!. When would 0.4.1 be pushed to remote? |
I'll hopefully get this released sometime over the next few days. Thanks. |
Hi ,
I wanted to enforce this constraint. There is a list of Experiences which is not required but if present then there should be at least one object .I have configured it in the following fashion
This adds a @SiZe validation constraint which fails even if you dont provide any experiences object.I want it to fail only if the experiences is empty.Let me know how to configure this
The text was updated successfully, but these errors were encountered: