Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import javax.ws.rs.ext.ContextResolver;
  2. import org.codehaus.jackson.map.ObjectMapper;
  3. import org.codehaus.jackson.map.SerializationConfig;
  4. import org.codehaus.jackson.map.DeserializationConfig;
  5. import javax.ws.rs.ext.Provider;
  6. import javax.ws.rs.Produces;
  7. import java.text.SimpleDateFormat;
  8. @Provider
  9. @Produces("application/json")
  10. public class JacksonConfigurator implements ContextResolver<ObjectMapper> {
  11.  
  12. private ObjectMapper mapper = new ObjectMapper();
  13.  
  14. public JacksonConfigurator() {
  15. SerializationConfig serConfig = mapper.getSerializationConfig();
  16. serConfig.setDateFormat(new SimpleDateFormat(<my format>));
  17. DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
  18. deserializationConfig.setDateFormat(new SimpleDateFormat(<my format>));
  19. mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
  20. }
  21.  
  22. @Override
  23. public ObjectMapper getContext(Class<?> arg0) {
  24. return mapper;
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement