JSON Schema reflects the fact that Jackson serializes URLs as JSON
Strings -- it wouldn't make much sense to report it as Object since
that is not its serialization. So this part works the way I would
expect it to be: JSON Schema defines the way JSON structures work, not
what is semantic view of your objects.

If you do want to change this, however, you can implement and register
custom JsonSerializer for URL.class (register via SimpleModule),
including implementation of:

    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper
visitor, JavaType type)

which is the callback that JSON Schema module receives and uses to
generate JSON Schema.
You will need to call various methods in `visitor`.

Alternatively you could serialize your URL-equivalent information as a
POJO and not java.net.URL: that way you can expose properties the way
you want.

-+ Tatu +-


On Tue, Mar 28, 2017 at 5:12 AM, Jonathan Kaplan
<foralltheemptin...@gmail.com> wrote:
> I have been creating services which expose JSON Schema so that forms can be
> created programmatically, this includes having metadata with validation.
>
> One of the POJOs which is converted to a JSON schema has a URL field.
> My first expectation was that when the schema is generated the type would be
> complex and reference the java.net.URL definition. However when the schema
> is generated the type is a String.
>
>
> I have considered putting an additional property to indicate that the field
> is a URL and should be validated as a URL, however I thought it would be
> cleaner to do it another way.
>
> I would like to try one of two options.
> The first option would be for me to add a new custom primitive type and
> return it instead of String, and the second option I would fall back on is
> to override String and return an object type with a reference to a JSON
> schema which represents a URL object.
> How would I go about overriding the natural type to solve this? Either of
> the two solutions are fine, however I am quite interested in the creation of
> my own custom primitive definitions instead of references to object schemas
> for this situation.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to