List of usage examples for com.fasterxml.jackson.jaxrs.cfg AnnotationBundleKey AnnotationBundleKey
public AnnotationBundleKey(Annotation[] annotations, Class<?> type)
From source file:nl.knaw.huygens.timbuctoo.rest.providers.HTMLProviderHelper.java
/** * Returns an object writer for a class with the specified annotations. * <ul>//w w w . j a v a 2s . c o m * <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; }