package shst.medicina.fichasclinicas.webservices.jaxrs; import java.text.SimpleDateFormat; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.ext.ContextResolver; import javax.ws.rs.ext.Provider; import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility; import org.codehaus.jackson.annotate.JsonMethod; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig.Feature; import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; @Provider @Produces(MediaType.APPLICATION_JSON) public class ObjectMapperResolver implements ContextResolver { private final ObjectMapper mapper; public ObjectMapperResolver() { mapper = new ObjectMapper(); mapper.enable(Feature.INDENT_OUTPUT); //mapper.setSerializationInclusion(Inclusion.NON_EMPTY); mapper.setVisibility(JsonMethod.GETTER, Visibility.NONE); mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY); // para formatar as datas em ISO8601 // -datas normais mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")); // -datas em java.sql.date mapper.registerModule(new JSONSQLDateSerializerModule()); } @Override public ObjectMapper getContext(Class type) { return mapper; } }