Java tutorial
/* * Copyright (C) 2013 Project-Phoenix * * This file is part of library. * * library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * library 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 * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with library. If not, see <http://www.gnu.org/licenses/>. */ package de.phoenix.rs; 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.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; import com.fasterxml.jackson.datatype.joda.JodaModule; @Provider @Produces(MediaType.APPLICATION_JSON) /** * Provider class to config the jackson provider */ public class JacksonConfigurator implements ContextResolver<ObjectMapper> { private ObjectMapper mapper = new ObjectMapper(); public JacksonConfigurator() { // Support joda datetime mapper.registerModule(new JodaModule()); mapper.enableDefaultTyping(); mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.WRAPPER_OBJECT); mapper.setSerializationInclusion(Include.NON_NULL); } @Override public ObjectMapper getContext(Class<?> arg0) { return mapper; } }