io.swagger.util.ResponseDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-all Show documentation
Show all versions of swagger-all Show documentation
swagger-all is a rebundled verison of Swagger as one OSGi bundle.
The 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 io.swagger.models.*;
import java.io.IOException;
public class ResponseDeserializer extends JsonDeserializer {
@Override
public Response deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException {
JsonNode node = jp.getCodec().readTree(jp);
JsonNode sub = node.get("$ref");
if (sub != null) {
return Json.mapper().convertValue(node, RefResponse.class);
} else {
Response response = Json.responseMapper().convertValue(node, Response.class);
return response;
}
}
}