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

JavaJaxRS.jacksonJsonProvider.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
package {{apiPackage}};

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

{{#java8}}
import com.fasterxml.jackson.datatype.jsr310.*;
{{/java8}}
{{^java8}}
import com.fasterxml.jackson.datatype.joda.*;
{{/java8}}

import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;

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

@Provider
@Produces({MediaType.APPLICATION_JSON})
public class JacksonJsonProvider extends JacksonJaxbJsonProvider {

    public JacksonJsonProvider() {

        ObjectMapper objectMapper = new ObjectMapper()
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
{{#java8}}
            .registerModule(new JavaTimeModule())
{{/java8}}
{{^java8}}
            .registerModule(new JodaModule())
{{/java8}}
            .setDateFormat(new RFC3339DateFormat());

        setMapper(objectMapper);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy