Question re default keyword on objects
andye2004 opened this issue · comments
I'm wondering if there would be any appetite for adding a recognised value as a marker to instantiate an empty instance of an object, if the object is marked with the default keyword?
This is a fairly contrived example but consider the folowing foo-bar schema snippet:
{
"title": "Foo Bar Schema",
"type": "object",
"properties": {
"foo": {
"title": "foo",
"type": "object",
"default": "instance",
"properties": {
"title": "bar",
"type": "string",
"default": "foobar"
}
},
"bar": {
"title": "bar",
"type": "string",
"default": "bar"
}
}
}
When the generate
target is run we end up with two pojos, Foo.java
and FooBar.java
, with FooBar.java
containing a foo
property as follows:-
...
private Foo foo = null;
...
It would be good if, based on a known value being used as the default, e.g. "default": "instance"
, the following code could be generated instead:
...
private Foo foo = new Foo();
...
I've used the word instance
in the example but the actual value could be made configurable to fit with different organisational requirements.
I'd be happy to provide a PR if it's something that would be accepted into the project.