From 2044f24ce44cb2e77cbb2dfe45a885af5ea2a296 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Mon, 12 Mar 2018 14:28:43 +0100 Subject: [PATCH] Adding custom (de)serialization --- .../coremanager/config/JacksonConfig.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/no/nibio/vips/coremanager/config/JacksonConfig.java diff --git a/src/main/java/no/nibio/vips/coremanager/config/JacksonConfig.java b/src/main/java/no/nibio/vips/coremanager/config/JacksonConfig.java new file mode 100644 index 0000000..b2e3f15 --- /dev/null +++ b/src/main/java/no/nibio/vips/coremanager/config/JacksonConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 NIBIO <http://www.nibio.no/>. + * + * This file is part of VIPSCoreManager. + * VIPSCore is free software: you can redistribute it and/or modify + * it under the terms of the NIBIO Open Source License as published by + * NIBIO, either version 1 of the License, or (at your option) any + * later version. + * + * VIPSCoreManager is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * NIBIO Open Source License for more details. + * + * You should have received a copy of the NIBIO Open Source License + * along with VIPSCoreManager. If not, see <http://www.nibio.no/licenses/>. + * + */ + +package no.nibio.vips.coremanager.config; + +import com.bedatadriven.jackson.datatype.jts.JtsModule; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import javax.ws.rs.Consumes; + +/** + * This config ensures that Jackson serializes dates as [ISO-8601 ]-compliant notation, + * and not a timestamp. Also that JTS objects are hopefully handled correctly + * @copyright 2018 <a href="http://www.nibio.no/">NIBIO</a> + * @author Tor-Einar Skog <tor-einar.skog@nibio.no> + */ +@Provider +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class JacksonConfig implements ContextResolver<ObjectMapper>{ + private final ObjectMapper objectMapper; + + public JacksonConfig() + { + objectMapper = new ObjectMapper(); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.registerModule(new JtsModule()); + } + + @Override + public ObjectMapper getContext(Class<?> objectType) + { + return objectMapper; + } +} -- GitLab