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

Optional Support #122

Open
yehuda-c opened this issue Feb 8, 2017 · 5 comments
Open

Optional Support #122

yehuda-c opened this issue Feb 8, 2017 · 5 comments
Labels
testcase-needed Need a reproduction of the issue (if any) to proceed

Comments

@yehuda-c
Copy link

yehuda-c commented Feb 8, 2017

Would be great if there was a way to configure this to serialize / deserialize json schema fields using Java 8 Optionals, so that fields of type T with required=false are deserialized to Optional and fields with required=true are deserialized to T rather than needing to use @JsonAttribute annotations.

@cowtowncoder
Copy link
Member

I am not sure how this is related to what this module does, JSON Schema generation?

@yehuda-c
Copy link
Author

yehuda-c commented Feb 9, 2017

JSON Schema generation will have a required field set to true or false. If this is settable based on whether the POJO contains an Optional, that would be amazing. For example:

{
  "type": "object",
  "properties": {
    "street_address": { "type": "string" },
    "city":           { "type": "string" },
    "state":          { "type": "string" }
  },
  "required": ["state"]
}

Would produce the pojo

public class Example {
    Optional<String> streetAddress;
    Optional<String> city;
    String state;
}

Does that explain this better?

@cowtowncoder
Copy link
Member

@yehudacohen Yes, that helps. Now, I was under impression that Optional (and other "reference types") did indeed set required to false, but if this is not the case it should be changed to do so.
Reverse (non-Optional marked as required) can not be made to work easily, although explicit required=true for @JsonProperty does do that.

Which version have you tried this with? Just want to verify that behavior you see is the latest one with 2.8.6.

@owulff
Copy link

owulff commented Sep 4, 2018

I'm looking for this feature (generate Optional generic) as well to be able to differentiate between a field which is set to null (default initialized) and not sent (optional).

@cowtowncoder cowtowncoder added the testcase-needed Need a reproduction of the issue (if any) to proceed label Sep 5, 2018
@cowtowncoder
Copy link
Member

At this point I would need to know exactly what THIS module would need to do differently.
Since module does not serialize/deserialize anything, either directly, or via jackson-databind, I wonder if this belongs to some other tool like "schema to pojo" generators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testcase-needed Need a reproduction of the issue (if any) to proceed
Projects
None yet
Development

No branches or pull requests

3 participants