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

Schema generates multiple type qualifiers for Date, int, long data types #14

Closed
aruld opened this issue Aug 17, 2013 · 3 comments
Closed
Milestone

Comments

@aruld
Copy link

aruld commented Aug 17, 2013

public class Employee {

  protected Date birthDt;
  protected String name;
  public Date getBirthDt() {
    return birthDt;
  }

  public void setBirthDt(Date value) {
    this.birthDt = value;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public static void main(String[] args) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper);
    JsonSchema jsonSchema = generator.generateSchema(Employee.class);
    System.out.println(mapper.writeValueAsString(jsonSchema));
  }
}

The code produces the JSON schema with redundant types for Date field.

{"type": "object", "properties": {
  "name": {
    "type": "string"
  },
  "birthDt": {
    "type": "number",
    "format": "UTC_MILLISEC",
    "type": "integer"
  }
}}
@aruld
Copy link
Author

aruld commented Aug 17, 2013

Deprecated JSON schema that comes with jackson-databind-2.2.2.jar works differently though. Here is the schema produced.

{"type": "object", "properties": {
  "birthDt": {
    "type": "number"
  },
  "name": {
    "type": "string"
  }
}}

@aruld
Copy link
Author

aruld commented Aug 18, 2013

Btw, this problem is not just with Date type. It occurs to long and int types.

{"type": "object", "properties": {
  "doubleProperty": {
    "type": "number"
  },
  "name": {
    "type": "string"
  },
  "floatProperty": {
    "type": "number"
  },
  "longProperty": {
    "type": "number",
    "type": "integer"
  },
  "birthDt": {
    "type": "number",
    "format": "UTC_MILLISEC",
    "type": "integer"
  },
  "intProperty": {
    "type": "number",
    "type": "integer"
  }
}}

@cowtowncoder
Copy link
Member

Duplication was caused by unnecessary 'type' fields (although Jackson type id handler should actually be able to coalesce these but...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants