Example usage for com.fasterxml.jackson.jaxrs.json JsonEndpointConfig forWriting

List of usage examples for com.fasterxml.jackson.jaxrs.json JsonEndpointConfig forWriting

Introduction

In this page you can find the example usage for com.fasterxml.jackson.jaxrs.json JsonEndpointConfig forWriting.

Prototype

public static JsonEndpointConfig forWriting(ObjectWriter writer, Annotation[] annotations,
            String defaultJsonpMethod) 

Source Link

Usage

From source file:nl.knaw.huygens.timbuctoo.rest.providers.HTMLProviderHelper.java

/**
 * Returns an object writer for a class with the specified annotations.
 * <ul>//w  ww.  j av  a  2  s.  com
 * <li>The current implementation is not thread safe.</li>
 * <li>Apparently uses undocumented features of Jackson. In version 2.1 it used
 * <code>com.fasterxml.jackson.jaxrs.json.util.AnnotationBundleKey</code> and
 * <code>com.fasterxml.jackson.jaxrs.json.annotation.EndpointConfig</code>.
 * In Jackson 2.2 the first of these classes was moved to a different package,
 * and the second was replaced by <code>JsonEndpointConfig</code>.</li>
 * </ul>
 */
public ObjectWriter getObjectWriter(Annotation[] annotations) {
    AnnotationBundleKey key = new AnnotationBundleKey(annotations, AnnotationBundleKey.class);
    ObjectWriter writer = writers.get(key);
    if (writer == null) {
        // A quick hack to add custom serialization of the Reference type.
        SimpleModule module = new SimpleModule();
        module.addSerializer(new ReferenceSerializer(registry));
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(module);
        JsonEndpointConfig endpointConfig = JsonEndpointConfig.forWriting(mapper, annotations, null);
        writer = endpointConfig.getWriter();
        writers.put(key, writer);
    }
    return writer;
}