1 package fr.ifremer.quadrige2.synchro.server.technical;
2
3 /*-
4 * #%L
5 * Quadrige2 Core :: Quadrige2 Synchro server
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2017 Ifremer
10 * %%
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * #L%
24 */
25
26 import fr.ifremer.quadrige2.core.dao.technical.gson.Gsons;
27 import org.apache.commons.lang3.StringUtils;
28 import org.springframework.beans.factory.InitializingBean;
29 import org.springframework.http.HttpInputMessage;
30 import org.springframework.http.converter.HttpMessageNotReadableException;
31
32 import java.io.IOException;
33 import java.lang.reflect.Type;
34 import java.util.TimeZone;
35
36 /**
37 * Override default converter to use specific gson configuration :<ul>
38 * <li>multimap support</li>
39 * <li>date pattern</li>
40 * <li>...</li>
41 * </ul>
42 * @see Gsons
43 */
44 public class GsonHttpMessageConverter extends org.springframework.http.converter.json.GsonHttpMessageConverter
45 implements InitializingBean {
46
47 private String timezone = null;
48
49 public GsonHttpMessageConverter() {
50 super();
51 }
52
53 public void setTimezone(String timezone) {
54 this.timezone = timezone;
55 }
56
57 @Override
58 public void afterPropertiesSet() throws Exception {
59
60 // Init Gson
61 TimeZone tz = StringUtils.isNotBlank(timezone) ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault();
62 setGson(Gsons.newBuilder(tz).create());
63 }
64 }