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 0000000000000000000000000000000000000000..b2e3f154325d864c93fc5bfe727af283600f7885 --- /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; + } +}