Search in sources :

Example 1 with JsonPointer

use of com.fasterxml.jackson.core.JsonPointer in project torodb by torodb.

the class DescriptionFactoryWrapper method expectArrayFormat.

@Override
public JsonArrayFormatVisitor expectArrayFormat(JavaType convertedType) {
    final JsonPointer jsonPointer = getJsonPointer();
    return new JsonArrayFormatVisitor.Base(getProvider()) {

        @Override
        public void itemsFormat(JsonFormatVisitable handler, JavaType elementType) throws JsonMappingException {
            SerializerProvider p = getProvider();
            JsonSerializer<Object> s = p.findValueSerializer(elementType);
            s.acceptJsonFormatVisitor(new DescriptionFactoryWrapper(DescriptionFactoryWrapper.this, jsonPointer.append(JsonPointer.valueOf("/<index>")), p), elementType);
        }
    };
}
Also used : JsonFormatVisitable(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable) JavaType(com.fasterxml.jackson.databind.JavaType) JsonPointer(com.fasterxml.jackson.core.JsonPointer) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider)

Example 2 with JsonPointer

use of com.fasterxml.jackson.core.JsonPointer in project torodb by torodb.

the class DescriptionFactoryWrapper method expectObjectFormat.

@Override
public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType) {
    final JsonPointer jsonPointer = getJsonPointer();
    return new JsonObjectFormatVisitor.Base(getProvider()) {

        @Override
        public void property(BeanProperty prop) throws JsonMappingException {
            visitProperty(prop, false);
        }

        @Override
        public void optionalProperty(BeanProperty prop) throws JsonMappingException {
            visitProperty(prop, true);
        }

        private void visitProperty(BeanProperty prop, boolean optional) throws JsonMappingException {
            JsonPointer propPointer = jsonPointer.append(JsonPointer.valueOf("/" + prop.getName()));
            document(propPointer, prop);
            SerializerProvider p = getProvider();
            JsonSerializer<Object> s = p.findValueSerializer(prop.getType(), prop);
            s.acceptJsonFormatVisitor(new DescriptionFactoryWrapper(DescriptionFactoryWrapper.this, propPointer, p), prop.getType());
        }
    };
}
Also used : JsonPointer(com.fasterxml.jackson.core.JsonPointer) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) BeanProperty(com.fasterxml.jackson.databind.BeanProperty)

Example 3 with JsonPointer

use of com.fasterxml.jackson.core.JsonPointer in project torodb by torodb.

the class ConfigUtils method transformConstraintsValidation.

private static <T> IllegalArgumentException transformConstraintsValidation(Set<ConstraintViolation<T>> constraintViolations) {
    ConstraintViolation<T> constraintViolation = constraintViolations.iterator().next();
    Path path = constraintViolation.getPropertyPath();
    JsonPointer jsonPointer = toJsonPointer(path);
    return new IllegalArgumentException("Constraint validation errors at " + jsonPointer.toString() + ": " + constraintViolation.getMessage());
}
Also used : Path(javax.validation.Path) JsonPointer(com.fasterxml.jackson.core.JsonPointer)

Example 4 with JsonPointer

use of com.fasterxml.jackson.core.JsonPointer in project KaiZen-OpenAPI-Editor by RepreZen.

the class AbstractJsonHyperlinkDetector method detectHyperlinks.

@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    JsonDocument document = (JsonDocument) textViewer.getDocument();
    JsonPointer basePath = document.getPath(region);
    if (!canDetect(basePath)) {
        return null;
    }
    HyperlinkInfo info = getHyperlinkInfo(textViewer, region);
    if (info == null) {
        return null;
    }
    return doDetect(document, textViewer, info, basePath);
}
Also used : JsonPointer(com.fasterxml.jackson.core.JsonPointer) JsonDocument(com.reprezen.swagedit.core.editor.JsonDocument)

Example 5 with JsonPointer

use of com.fasterxml.jackson.core.JsonPointer in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonReferenceFactory method doCreate.

public JsonReference doCreate(String value, Object source) {
    String notNull = Strings.nullToEmpty(value);
    URI uri;
    try {
        uri = URI.create(notNull);
    } catch (NullPointerException | IllegalArgumentException e) {
        // try to encode illegal characters, e.g. curly braces
        try {
            uri = URI.create(URLUtils.encodeURL(notNull));
        } catch (NullPointerException | IllegalArgumentException e2) {
            return new JsonReference(null, null, false, false, false, source);
        }
    }
    String fragment = uri.getFragment();
    JsonPointer pointer = null;
    try {
        pointer = JsonPointer.compile(Strings.emptyToNull(fragment));
    } catch (IllegalArgumentException e) {
    // let the pointer be null
    }
    uri = uri.normalize();
    boolean absolute = uri.isAbsolute();
    boolean local = !absolute && uri.getPath().isEmpty();
    // should warn when using curly braces
    boolean warnings = notNull.contains("{") || uri.toString().contains("}");
    return new JsonReference(uri, pointer, absolute, local, warnings, source);
}
Also used : JsonPointer(com.fasterxml.jackson.core.JsonPointer) URI(java.net.URI)

Aggregations

JsonPointer (com.fasterxml.jackson.core.JsonPointer)18 ArrayList (java.util.ArrayList)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)2 SwaggerHyperlink (com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink)2 AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)2 IRegion (org.eclipse.jface.text.IRegion)2 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)2 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 JsonFormatVisitable (com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1 Model (com.reprezen.swagedit.core.model.Model)1 ObjectNode (com.reprezen.swagedit.core.model.ObjectNode)1 HttpMethod (io.swagger.models.HttpMethod)1 URI (java.net.URI)1