This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Simpe JacksonJaxbJsonProvider within JAX-RS activator

By: a guest on Aug 8th, 2012  |  syntax: Java  |  size: 1.29 KB  |  views: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package uk.co.jmkg.jaxrstesting.jaxrs;
  6.  
  7. import com.fasterxml.jackson.databind.SerializationFeature;
  8. import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
  9. import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
  10. import java.util.HashSet;
  11. import java.util.Set;
  12. import javax.ws.rs.ApplicationPath;
  13. import javax.ws.rs.core.Application;
  14. import uk.co.jmkg.jaxrstesting.resources.CustomerResource;
  15.  
  16. /**
  17.  *
  18.  * @author jamesgreen
  19.  */
  20. @ApplicationPath("/rest")
  21. public class Activator extends Application {
  22.  
  23.     @Override
  24.     public Set<Class<?>> getClasses() {
  25.         Set<Class<?>> classes = new HashSet<Class<?>>();
  26.         classes.add(CustomerResource.class);
  27.         return classes;
  28.     }
  29.    
  30.  
  31.     @Override
  32.     public Set<Object> getSingletons() {
  33.         Set<Object> objects = new HashSet<Object>();
  34.         JacksonJsonProvider provider = new JacksonJaxbJsonProvider();
  35. //        provider.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
  36.         provider.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
  37.         provider.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  38.         objects.add(provider);
  39.         return objects;
  40.     }
  41.    
  42. }
clone this paste RAW Paste Data