Properties in object constructor are required.
See original GitHub issueJSON object properties which are not required are being set as required when setting those values in that objects constructor.
public class Example {
public Example() {
field1 = 4;
}
@JsonPropertyDescription("asdsad")
private Object field1;
@JsonPropertyDescription("asdsad")
private Object field2;
}
Then in my schema I see:
"required" : [ "field1"],
This is trouble for me since I never specified.
@JsonProperty(required=true)
and even when I say
@JsonProperty(required=false)
it shows up as required anyway.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Object.prototype.constructor - JavaScript - MDN Web Docs
The constructor data property of an Object instance returns a reference to the constructor function that created the instance object.
Read more >JavaScript Constructors: What You Need to Know - Rollbar
The purpose of a constructor is to create a new object and set values for any existing object properties. What Happens When A...
Read more >required modifier - C# Reference - Microsoft Learn
The required modifier indicates that the field or property it's applied to must be initialized by all constructors or by using an object ......
Read more >how do you add properties to an object constructor function
You can simple add a private variable to your constructor: function Hotel(name) { var private = 'private'; this.name = name; };.
Read more >Constructor, operator "new" - The Modern JavaScript Tutorial
The regular {...} syntax allows us to create one object. But often we need to create many similar objects, like multiple users or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @kog for spotting the explanation.
@mbap: Since you are using Jackson and Java with primitives, your code cannot know if field1 (int) was set to “0” in json or if it was not included in json at all. If you need that sort of info, then field1 must be Integer. It makes no point in setting a field ‘not required’, if your code cannot know if you got it or not.
Awesome thanks for the clear explanation.