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

io.swagger.util.PathDeserializer Maven / Gradle / Ivy

There is a newer version: 2.0.0-rc2
Show newest version
package io.swagger.util;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import io.swagger.models.*;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.io.IOException;

public class PathDeserializer extends JsonDeserializer {
    @Override
    public Path deserialize(JsonParser jp, DeserializationContext ctxt)
            throws IOException {

        JsonNode node = jp.getCodec().readTree(jp);
        JsonNode sub = node.get("$ref");

        Path result;

        if(sub != null) {
            result = Json.mapper().convertValue(node, RefPath.class);
        } else {
            result = Json.pathMapper().convertValue(node, Path.class);
        }

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy