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

com.symphony.bdk.http.jersey2.JSON Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package com.symphony.bdk.http.jersey2;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import jakarta.ws.rs.ext.ContextResolver;
import org.apiguardian.api.API;
import org.openapitools.jackson.nullable.JsonNullableModule;

import java.text.DateFormat;


@API(status = API.Status.INTERNAL)
public class JSON implements ContextResolver {

  private final ObjectMapper mapper;

  public JSON() {
    this.mapper = new ObjectMapper();
    this.mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    this.mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
    this.mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    this.mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
    this.mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
    this.mapper.setDateFormat(new RFC3339DateFormat());
    this.mapper.registerModule(new JavaTimeModule());
    this.mapper.registerModule(new JsonNullableModule());
  }

  /**
   * Set the date format for JSON (de)serialization with Date properties.
   * @param dateFormat Date format
   */
  public void setDateFormat(DateFormat dateFormat) {
    mapper.setDateFormat(dateFormat);
  }

  @Override
  public ObjectMapper getContext(Class type) {
    return this.mapper;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy