-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJacksonConfig.mustache
More file actions
44 lines (34 loc) · 1.2 KB
/
JacksonConfig.mustache
File metadata and controls
44 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package {{invokerPackage}};
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
{{#java8}}
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
{{/java8}}
{{^java8}}
import com.fasterxml.jackson.datatype.joda.JodaModule;
{{/java8}}
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver<ObjectMapper> {
private static final Logger LOG = LoggerFactory.getLogger(JacksonConfig.class);
private ObjectMapper objectMapper;
public JacksonConfig() throws Exception {
this.objectMapper = new ObjectMapper();
{{#java8}}
this.objectMapper.registerModule(new JavaTimeModule());
{{/java8}}
{{^java8}}
this.objectMapper.registerModule(new JodaModule());
{{/java8}}
// sample to convert any DateTime to readable timestamps
//this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
}
public ObjectMapper getContext(Class<?> objectType) {
return objectMapper;
}
}