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

io.swagger.inflector.processors.JsonProvider Maven / Gradle / Ivy

There is a newer version: 2.0.12
Show newest version
package io.swagger.inflector.processors;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.swagger.util.Json;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

@Provider
public class JsonProvider implements ContextResolver {
    private final ObjectMapper objectMapper;
    private boolean prettyPrint;

    public JsonProvider() {
        objectMapper = Json.mapper();
    }

    public JsonProvider(boolean prettyPrint) {
        this();
        this.prettyPrint = prettyPrint;
    }

    @Override
    public ObjectMapper getContext(Class type) {
        if(this.prettyPrint) {
            objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
        }

        return objectMapper;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy