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

com.onegini.sdk.util.IdpObjectMapper Maven / Gradle / Ivy

There is a newer version: 5.92.0
Show newest version
/*
 * Copyright 2013-2020 Onegini b.v.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.onegini.sdk.util;


import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;

/**
 * This object mapper implementation is intended to be used for serializing/deserializing
 * communication in with the idp-core APIs. Please be aware that any applying
 * any changes to this class may break the compatibility with idp-core product.
 *
 * Please look into ExtensionObjectMapper implementation in idp-extension-sdk if you are
 * interested in getting insight or changing the serialization behaviour in idp-extension APIs.
 */
public class IdpObjectMapper extends ObjectMapper {

  public IdpObjectMapper() {
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true);
    configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);

    registerModule(new AfterburnerModule());
    registerModule(new Jdk8Module());
    registerModule(new GuavaModule());
    registerModule(new JavaTimeModule());

    setDateFormat(new ISO8601DateFormat());

    setSerializationInclusion(NON_EMPTY);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy