| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.config;
|
1 |
package com.spice.profitmandi.web.config;
|
| 2 |
|
2 |
|
| 3 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 4 |
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
- |
|
| 5 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
- |
|
| 6 |
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
- |
|
| 7 |
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
- |
|
| 8 |
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
- |
|
| 9 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
4 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 10 |
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
|
5 |
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
|
| 11 |
import org.springframework.beans.factory.annotation.Autowired;
|
6 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 12 |
import org.springframework.context.annotation.Bean;
|
- |
|
| 13 |
import org.springframework.context.annotation.ComponentScan;
|
7 |
import org.springframework.context.annotation.ComponentScan;
|
| 14 |
import org.springframework.context.annotation.Configuration;
|
8 |
import org.springframework.context.annotation.Configuration;
|
| 15 |
import org.springframework.format.FormatterRegistry;
|
9 |
import org.springframework.format.FormatterRegistry;
|
| 16 |
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
|
10 |
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
|
| 17 |
import org.springframework.http.MediaType;
|
11 |
import org.springframework.http.MediaType;
|
| 18 |
import org.springframework.http.converter.HttpMessageConverter;
|
12 |
import org.springframework.http.converter.HttpMessageConverter;
|
| 19 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
13 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
| 20 |
import org.springframework.web.servlet.config.annotation.*;
|
14 |
import org.springframework.web.servlet.config.annotation.*;
|
| 21 |
|
15 |
|
| 22 |
import java.time.LocalDateTime;
|
- |
|
| 23 |
import java.time.format.DateTimeFormatter;
|
- |
|
| 24 |
import java.time.format.DateTimeFormatterBuilder;
|
- |
|
| 25 |
import java.util.List;
|
16 |
import java.util.List;
|
| 26 |
|
17 |
|
| 27 |
@EnableWebMvc
|
18 |
@EnableWebMvc
|
| 28 |
@Configuration
|
19 |
@Configuration
|
| 29 |
@ComponentScan({ "com.spice.profitmandi.*" })
|
20 |
@ComponentScan({ "com.spice.profitmandi.*" })
|
| Line 36... |
Line 27... |
| 36 |
AuthenticationInterceptor authenticationInterceptor;
|
27 |
AuthenticationInterceptor authenticationInterceptor;
|
| 37 |
|
28 |
|
| 38 |
@Autowired
|
29 |
@Autowired
|
| 39 |
RoleInterceptor roleInterceptor;
|
30 |
RoleInterceptor roleInterceptor;
|
| 40 |
|
31 |
|
| - |
|
32 |
@Autowired
|
| - |
|
33 |
ObjectMapper objectMapper;
|
| - |
|
34 |
|
| 41 |
@Override
|
35 |
@Override
|
| 42 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
36 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
| 43 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
37 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
| 44 |
}
|
38 |
}
|
| 45 |
|
39 |
|
| Line 61... |
Line 55... |
| 61 |
registrar.registerFormatters(registry);
|
55 |
registrar.registerFormatters(registry);
|
| 62 |
}
|
56 |
}
|
| 63 |
|
57 |
|
| 64 |
@Override
|
58 |
@Override
|
| 65 |
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
59 |
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
| 66 |
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
60 |
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
| 67 |
}
|
61 |
}
|
| 68 |
|
62 |
|
| 69 |
@Bean
|
- |
|
| 70 |
public ObjectMapper objectMapper() {
|
- |
|
| 71 |
DateTimeFormatter df = new DateTimeFormatterBuilder().parseCaseInsensitive()
|
- |
|
| 72 |
.append(DateTimeFormatter.ISO_LOCAL_DATE).optionalStart().appendLiteral('T').optionalEnd()
|
- |
|
| 73 |
.appendLiteral(' ').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
|
- |
|
| 74 |
DateTimeFormatter sf = new DateTimeFormatterBuilder().parseCaseInsensitive()
|
- |
|
| 75 |
.append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME)
|
- |
|
| 76 |
.toFormatter();
|
- |
|
| 77 |
LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
|
- |
|
| 78 |
LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
|
- |
|
| 79 |
JavaTimeModule jtm = new JavaTimeModule();
|
- |
|
| 80 |
jtm.addSerializer(LocalDateTime.class, serializer);
|
- |
|
| 81 |
jtm.addDeserializer(LocalDateTime.class, deserializer);
|
- |
|
| 82 |
ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule())
|
- |
|
| 83 |
.registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Module
|
- |
|
| 84 |
return mapper;
|
- |
|
| 85 |
}
|
- |
|
| 86 |
|
63 |
|
| 87 |
@Override
|
64 |
@Override
|
| 88 |
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
65 |
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
| 89 |
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
|
66 |
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
|
| 90 |
}
|
67 |
}
|