All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.module.jsonSchema.factories.VisitorContext Maven / Gradle / Ivy

Go to download

Add-on module for Jackson (http://jackson.codehaus.org) to support JSON Schema (http://tools.ietf.org/html/draft-zyp-json-schema-03) version 3 generation.

The newest version!
package com.fasterxml.jackson.module.jsonSchema.factories;

import com.fasterxml.jackson.databind.JavaType;

import java.util.HashSet;

public class VisitorContext
{
    private final HashSet seenSchemas = new HashSet();

    public String addSeenSchemaUri(JavaType aSeenSchema) {
        if (aSeenSchema != null && !aSeenSchema.isPrimitive()) {
            seenSchemas.add(aSeenSchema);
            return javaTypeToUrn(aSeenSchema);
        }
        return null;
    }

    public String getSeenSchemaUri(JavaType aSeenSchema) {
        return (seenSchemas.contains(aSeenSchema)) ? javaTypeToUrn(aSeenSchema) : null;
    }

    public String javaTypeToUrn(JavaType jt) {
        return "urn:jsonschema:" + jt.toCanonical().replace('.', ':').replace('$', ':');
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy