Skip to content
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

Option to create constructors (with all fields, or with required fields) #231

Closed
monksy opened this issue Jul 31, 2014 · 4 comments
Closed
Milestone

Comments

@monksy
Copy link

monksy commented Jul 31, 2014

At the moment it's a little messy with creating new instances of the POJOs with the builders. Could we get an option that would create an additional constructor to define the required fields?

Right now to create something of the following schema:

 Obj { name: asdf, age: 32; state:NC} 

You would have to invoke it by: (with builders enabled)

new Obj().withName("asdf").withAge(32).withState("NC")

Rather than [what I'm suggesting]

new Obj("asdf", 32, "NC")
@talios
Copy link

talios commented Dec 18, 2014

I was just about to raise an issue similar to this. JSON-Schema (Validation) has the "required" keyword to signify which fields are mandatory for a schema object.

It would probably make sense support that rather than just adding an epic constructor with all fields.

So something like:

  {
    "type": "object",
    "$schema": "http://json-schema.org/schema",
    "description": "A thing",
    "id": "thing",
    "properties": {
      "id": {
        "type": "string"
      },
      "description": {
        "type": "string"
      }
    },
    "required": ["id", "description"]
  }

Should generate a constructor for (String id, String description) in the order specified.

@talios
Copy link

talios commented Dec 18, 2014

Interestingly, I originally had "required": true" against each property in my schemas, however I see that required is not mentioned in the core JSON-Schema spec, tho jsonschema2java generates @NotNull annotations for those? That should probably also change. It looks like this may have changed in the draft-03 spec..

@andrewmains12
Copy link
Contributor

Took a stab at this here

@joelittlejohn
Copy link
Owner

Closed by #283

@joelittlejohn joelittlejohn added this to the 0.4.8 milestone Feb 9, 2015
@joelittlejohn joelittlejohn changed the title Option to create a constructor with all of the required fields Option to create constructors (with all fields, or with required fields) Feb 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants