1

I have a POJO annotated with hibernate validator annotations:

public class UserDto {
    @Length(min = 2, max = 5)
    @NotEmpty
    private String name;
    @Length(min = 8)
    @NotEmpty
    private String password;

    //getters and setters
}

From this POJO I want to be able to generate a schema that looks like this:

{"type": "object",
  "$schema": "http://json-schema.org/draft-04/schema#",
    "properties": {
        "password": {
            "type": "string",
            "minLength" : 2,
            "maxLength" : 5,
            "required" : true
        },
        "name": {
            "type": "string"
            "minLength" : 8,
            "required" : true
        }
    }
}

Is there a library that is able to do this?

I'm looking at https://github.com/FasterXML/jackson but I don't see out of the box support for this.

Pointers will be very welcomed! Thank you!

vlashel
  • 345
  • 2
  • 15
  • Have you ever found an answer? – Gabriel Ruiu Oct 20 '14 at 17:00
  • https://github.com/cponomaryov/jackson-module-jsonSchema/tree/master/src/main/java/com/fasterxml/jackson/module/jsonSchema There's no support for this, but this is being developed in jackson, look at customProperties and validation packages, you'll figure out how to do add another annotations. – vlashel Oct 21 '14 at 05:36
  • The problem is jackson generates draft 3 schemas, I made a convertor to suite my requirments, and converted schemas generated by jackson into draft 4, there's also https://github.com/reinert/JJSchema , it can generate draft 4, but it generates schemas based on its custom annotations. – vlashel Oct 21 '14 at 05:55
  • @vlashel You mentioned it's "being developed". Do you know anything about the effort? Do you have a pointer to any discussion about it? – ccleve Nov 07 '14 at 22:38
  • https://github.com/FasterXML/jackson-module-jsonSchema/pull/32 – vlashel Nov 10 '14 at 09:03

0 Answers0