| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.config;
|
1 |
package com.spice.profitmandi.web.config;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.io.IOException;
|
| - |
|
4 |
import java.sql.Timestamp;
|
| - |
|
5 |
import java.time.LocalDateTime;
|
| - |
|
6 |
import java.time.ZoneId;
|
| - |
|
7 |
import java.time.ZonedDateTime;
|
| - |
|
8 |
import java.time.format.DateTimeFormatter;
|
| - |
|
9 |
import java.util.List;
|
| - |
|
10 |
|
| 3 |
import org.springframework.beans.factory.annotation.Autowired;
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 4 |
import org.springframework.context.annotation.Bean;
|
12 |
import org.springframework.context.annotation.Bean;
|
| 5 |
import org.springframework.context.annotation.ComponentScan;
|
13 |
import org.springframework.context.annotation.ComponentScan;
|
| 6 |
import org.springframework.context.annotation.Configuration;
|
14 |
import org.springframework.context.annotation.Configuration;
|
| - |
|
15 |
import org.springframework.http.converter.HttpMessageConverter;
|
| - |
|
16 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
| 7 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
17 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 8 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
18 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
| 9 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
19 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
| 10 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
20 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
| 11 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
21 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
| 12 |
|
22 |
|
| - |
|
23 |
import com.fasterxml.jackson.core.JsonGenerator;
|
| - |
|
24 |
import com.fasterxml.jackson.core.JsonParser;
|
| - |
|
25 |
import com.fasterxml.jackson.databind.DeserializationContext;
|
| - |
|
26 |
import com.fasterxml.jackson.databind.JsonDeserializer;
|
| - |
|
27 |
import com.fasterxml.jackson.databind.JsonSerializer;
|
| - |
|
28 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| - |
|
29 |
import com.fasterxml.jackson.databind.SerializationFeature;
|
| - |
|
30 |
import com.fasterxml.jackson.databind.SerializerProvider;
|
| - |
|
31 |
import com.fasterxml.jackson.databind.ser.std.DateSerializer;
|
| - |
|
32 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 13 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 14 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
34 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
| 15 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
35 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 16 |
|
36 |
|
| 17 |
import springfox.documentation.builders.PathSelectors;
|
37 |
import springfox.documentation.builders.PathSelectors;
|
| Line 27... |
Line 47... |
| 27 |
@ComponentScan("com.spice.profitmandi.*")
|
47 |
@ComponentScan("com.spice.profitmandi.*")
|
| 28 |
public class WebMVCConfig extends WebMvcConfigurerAdapter{
|
48 |
public class WebMVCConfig extends WebMvcConfigurerAdapter{
|
| 29 |
|
49 |
|
| 30 |
private static final String RESOURCES_PATTERN="/resources/**";
|
50 |
private static final String RESOURCES_PATTERN="/resources/**";
|
| 31 |
private static final String RESOURCES_LOCATION="/resources/";
|
51 |
private static final String RESOURCES_LOCATION="/resources/";
|
| - |
|
52 |
public static final DateTimeFormatter FORMATTER =DateTimeFormatter.ofPattern("dd::MM::yyyy");
|
| 32 |
|
53 |
|
| 33 |
@Autowired
|
54 |
@Autowired
|
| 34 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
55 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
| 35 |
|
56 |
|
| 36 |
@Autowired
|
57 |
@Autowired
|
| Line 78... |
Line 99... |
| 78 |
"New Spice Solutions Pvt. Ltd.",
|
99 |
"New Spice Solutions Pvt. Ltd.",
|
| 79 |
"License of API",
|
100 |
"License of API",
|
| 80 |
"API license URL");
|
101 |
"API license URL");
|
| 81 |
return apiInfo;
|
102 |
return apiInfo;
|
| 82 |
}
|
103 |
}
|
| - |
|
104 |
|
| - |
|
105 |
@Override
|
| - |
|
106 |
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
| - |
|
107 |
|
| - |
|
108 |
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
| - |
|
109 |
super.configureMessageConverters(converters);
|
| - |
|
110 |
}
|
| - |
|
111 |
|
| - |
|
112 |
private ObjectMapper objectMapper() {
|
| - |
|
113 |
ObjectMapper objectMapper = new ObjectMapper();
|
| - |
|
114 |
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
| - |
|
115 |
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
| - |
|
116 |
javaTimeModule.addSerializer(java.sql.Date.class, new DateSerializer());
|
| - |
|
117 |
javaTimeModule.addDeserializer(Timestamp.class, new LocalDateDeserializer());
|
| - |
|
118 |
objectMapper.registerModule(javaTimeModule);
|
| - |
|
119 |
return objectMapper;
|
| - |
|
120 |
}
|
| - |
|
121 |
|
| - |
|
122 |
public class LocalDateSerializer extends JsonSerializer<Timestamp> {
|
| - |
|
123 |
|
| - |
|
124 |
@Override
|
| - |
|
125 |
public void serialize(Timestamp value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
| - |
|
126 |
|
| - |
|
127 |
ZonedDateTime z = value.toInstant().atZone(ZoneId.systemDefault());
|
| - |
|
128 |
String str = FORMATTER.format(z);
|
| - |
|
129 |
gen.writeString(str);
|
| - |
|
130 |
}
|
| - |
|
131 |
}
|
| - |
|
132 |
|
| - |
|
133 |
public class LocalDateDeserializer extends JsonDeserializer<Timestamp> {
|
| - |
|
134 |
|
| - |
|
135 |
@Override
|
| - |
|
136 |
public Timestamp deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
| - |
|
137 |
LocalDateTime dt = LocalDateTime.parse(p.getText(), FORMATTER);
|
| - |
|
138 |
// the date/time is in the default timezone
|
| - |
|
139 |
return Timestamp.from(dt.atZone(ZoneId.systemDefault()).toInstant());
|
| - |
|
140 |
}
|
| - |
|
141 |
}
|
| - |
|
142 |
|
| - |
|
143 |
|
| 83 |
}
|
144 |
}
|
| 84 |
|
145 |
|