Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.ws.rs.ext.ContextResolver;
- import org.codehaus.jackson.map.ObjectMapper;
- import org.codehaus.jackson.map.SerializationConfig;
- import org.codehaus.jackson.map.DeserializationConfig;
- import javax.ws.rs.ext.Provider;
- import javax.ws.rs.Produces;
- import java.text.SimpleDateFormat;
- @Provider
- @Produces("application/json")
- public class JacksonConfigurator implements ContextResolver<ObjectMapper> {
- private ObjectMapper mapper = new ObjectMapper();
- public JacksonConfigurator() {
- SerializationConfig serConfig = mapper.getSerializationConfig();
- serConfig.setDateFormat(new SimpleDateFormat(<my format>));
- DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
- deserializationConfig.setDateFormat(new SimpleDateFormat(<my format>));
- mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
- }
- @Override
- public ObjectMapper getContext(Class<?> arg0) {
- return mapper;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement