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

Support URI format properties with a default value using URI.create #664

Closed
ben-manes opened this issue Dec 16, 2016 · 2 comments
Closed
Milestone

Comments

@ben-manes
Copy link
Collaborator

{
  "type":"object",
  "properties": {
    "type": {
      "type": "string",
      "format": "uri",
      "default": "abc"
    },
    "types": {
      "items": {
        "type": "string",
        "format": "uri"
      },
      "uniqueItems": true,
      "type": "array",
      "default": [ "/abc/efg" ]
    }
  }
}

This generates the fields,

@JsonProperty("type")
private URI type = null;
@JsonProperty("types")
@JsonDeserialize(as = java.util.LinkedHashSet.class)
private Set<URI> types = new LinkedHashSet<URI>(Arrays.asList(null));

But when the format is removed it generates a a String value,

@JsonProperty("type")
private String type = "abc";
@JsonProperty("types")
@JsonDeserialize(as = java.util.LinkedHashSet.class)
private Set<String> types = new LinkedHashSet<String>(Arrays.asList("/abc/efg"));

Can we support creating default URIs? Presumably they could be private static fields.

@joelittlejohn
Copy link
Owner

joelittlejohn commented Dec 16, 2016

Absolutely, I think we can do this. I was a little surprised that this wasn't already supported :) I think URI.create will be sufficient. Of course the default will have to be a valid URI to avoid an exception.

I'm not really convinced about creating private static fields. I think we should simply assign these fields like:

@JsonProperty("type")
private URI type = URI.create("http://my/default");

with no indirection whatsoever.

@joelittlejohn joelittlejohn changed the title URI format with default generates null value Support URI format properties with a default value using URI.create Dec 16, 2016
@joelittlejohn
Copy link
Owner

I've changed the title here as I think this will be more helpful in the changelog.

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

2 participants