1 package fr.ifremer.quadrige3.synchro.server.technical; 2 3 /*- 4 * #%L 5 * Quadrige3 Core :: Quadrige3 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.quadrige3.core.dao.technical.gson.Gsons; 27 import org.apache.commons.lang3.StringUtils; 28 import org.springframework.beans.factory.InitializingBean; 29 30 import java.util.TimeZone; 31 32 /** 33 * Override default converter to use specific gson configuration :<ul> 34 * <li>multimap support</li> 35 * <li>date pattern</li> 36 * <li>...</li> 37 * </ul> 38 * @see Gsons 39 */ 40 public class GsonHttpMessageConverter extends org.springframework.http.converter.json.GsonHttpMessageConverter 41 implements InitializingBean { 42 43 private String timezone = null; 44 45 public GsonHttpMessageConverter() { 46 super(); 47 } 48 49 public void setTimezone(String timezone) { 50 this.timezone = timezone; 51 } 52 53 @Override 54 public void afterPropertiesSet() { 55 56 // Init Gson 57 TimeZone tz = StringUtils.isNotBlank(timezone) ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault(); 58 setGson(Gsons.newBuilder(tz).create()); 59 } 60 }