All Downloads are FREE. Search and download functionalities are using the official Maven repository.

handlebars.JavaJaxRS.resteasy.eap.JacksonConfig.mustache Maven / Gradle / Ivy

There is a newer version: 1.0.54
Show newest version
package {{invokerPackage}};

{{#jakarta}}
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.ContextResolver;
import jakarta.ws.rs.ext.Provider;
{{/jakarta}}
{{^jakarta}}
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
{{/jakarta}}

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
{{#java8}}
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
{{/java8}}
{{^java8}}
import com.fasterxml.jackson.datatype.joda.JodaModule;
{{/java8}}

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver {

    private static final Logger LOG = LoggerFactory.getLogger(JacksonConfig.class);

    private ObjectMapper objectMapper;

    public JacksonConfig() throws Exception {
        this.objectMapper = new ObjectMapper();
        
{{#java8}}        
        this.objectMapper.registerModule(new JavaTimeModule());
{{/java8}}
{{^java8}}
        this.objectMapper.registerModule(new JodaModule());
{{/java8}}

        // sample to convert any DateTime to readable timestamps
        //this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
    }
    
    public ObjectMapper getContext(Class objectType) {
        return objectMapper;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy