// Path: RosettaCore/src/main/java/com/hubspot/rosetta/databind/AutoDiscoveredModule.java
// public abstract class AutoDiscoveredModule extends Module {
// }
// 
// Path: RosettaCore/src/main/java/com/hubspot/rosetta/internal/RosettaModule.java
// @SuppressWarnings("serial")
// public class RosettaModule extends Module {
// 
//   @Override
//   public String getModuleName() {
//     return "RosettaModule";
//   }
// 
//   @Override
//   public Version version() {
//     return Version.unknownVersion();
//   }
// 
//   @Override
//   public void setupModule(SetupContext context) {
//     context.addBeanSerializerModifier(new StoredAsJsonBeanSerializerModifier());
// 
//     ObjectCodec codec = context.getOwner();
//     if (codec instanceof ObjectMapper) {
//       ObjectMapper mapper = (ObjectMapper) codec;
// 
//       context.insertAnnotationIntrospector(new RosettaAnnotationIntrospector(mapper));
// 
//       mapper.setSerializerProvider(new DefaultSerializerProvider.Impl());
//       mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
//       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//       mapper.setSerializationInclusion(Include.ALWAYS);
//     }
//   }
// }


import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.rosetta.databind.AutoDiscoveredModule;
import com.hubspot.rosetta.internal.RosettaModule;
  public static void setMapper(ObjectMapper mapper) {
    INSTANCE.set(mapper);
  }

  public static ObjectMapper cloneAndCustomize(ObjectMapper mapper) {
    mapper = mapper.copy();

    // ObjectMapper#registerModules doesn't exist in 2.1.x
    for (Module module : MODULES) {
      mapper.registerModule(module);
    }

    return mapper;
  }

  private ObjectMapper get() {
    return MAPPER.get();
  }

  private void set(ObjectMapper mapper) {
    MAPPER.set(cloneAndCustomize(mapper));
  }

  private void add(Module module) {
    MODULES.add(module);
    MAPPER.get().registerModule(module);
  }

  private static List<Module> defaultModules() {
    List<Module> defaultModules = new ArrayList<Module>();
// Path: RosettaCore/src/main/java/com/hubspot/rosetta/databind/AutoDiscoveredModule.java
// public abstract class AutoDiscoveredModule extends Module {
// }
// 
// Path: RosettaCore/src/main/java/com/hubspot/rosetta/internal/RosettaModule.java
// @SuppressWarnings("serial")
// public class RosettaModule extends Module {
// 
//   @Override
//   public String getModuleName() {
//     return "RosettaModule";
//   }
// 
//   @Override
//   public Version version() {
//     return Version.unknownVersion();
//   }
// 
//   @Override
//   public void setupModule(SetupContext context) {
//     context.addBeanSerializerModifier(new StoredAsJsonBeanSerializerModifier());
// 
//     ObjectCodec codec = context.getOwner();
//     if (codec instanceof ObjectMapper) {
//       ObjectMapper mapper = (ObjectMapper) codec;
// 
//       context.insertAnnotationIntrospector(new RosettaAnnotationIntrospector(mapper));
// 
//       mapper.setSerializerProvider(new DefaultSerializerProvider.Impl());
//       mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
//       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//       mapper.setSerializationInclusion(Include.ALWAYS);
//     }
//   }
// }


// Path: RosettaCore/src/main/java/com/hubspot/rosetta/Rosetta.java
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.rosetta.databind.AutoDiscoveredModule;
import com.hubspot.rosetta.internal.RosettaModule;

  public static void setMapper(ObjectMapper mapper) {
    INSTANCE.set(mapper);
  }

  public static ObjectMapper cloneAndCustomize(ObjectMapper mapper) {
    mapper = mapper.copy();

    // ObjectMapper#registerModules doesn't exist in 2.1.x
    for (Module module : MODULES) {
      mapper.registerModule(module);
    }

    return mapper;
  }

  private ObjectMapper get() {
    return MAPPER.get();
  }

  private void set(ObjectMapper mapper) {
    MAPPER.set(cloneAndCustomize(mapper));
  }

  private void add(Module module) {
    MODULES.add(module);
    MAPPER.get().registerModule(module);
  }

  private static List<Module> defaultModules() {
    List<Module> defaultModules = new ArrayList<Module>();
    defaultModules.add(new RosettaModule());