Skip to content
Snippets Groups Projects
Commit 2044f24c authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Adding custom (de)serialization

parent fbecce4f
No related branches found
No related tags found
No related merge requests found
/*
* 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment