package com.atlassian.stash.internal.rest.json;

import org.codehaus.jackson.Version;
import org.codehaus.jackson.map.Module;
import org.codehaus.jackson.map.module.SimpleModule;
import org.codehaus.jackson.map.module.SimpleSerializers;

/**
 * Jackson module that adds serializers for types introduced in Java 8.
 * <p>
 * As soon as Bitbucket is switched to a version of REST that provides Jackson 2,
 * this workaround should be replaced with a proper JDK8 types support for Jackson.
 * <p>
 * See BSERVDEV-11142
 */
public class Jdk8JacksonModule extends SimpleModule {

    public Jdk8JacksonModule() {
        super("Jdk8JacksonModule", new Version(1, 0, 0, null));
    }

    @Override
    public void setupModule(Module.SetupContext context) {
        SimpleSerializers serializers = new SimpleSerializers();
        serializers.addSerializer(new OptionalJsonSerializer());
        context.addSerializers(serializers);
    }
}