package io.intercom.api;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;

public class MapperSupport {

    public static ObjectMapper objectMapper() {
        final ObjectMapper om = Holder.INSTANCE;
        configure(om);
        return om;
    }

    private static void configure(ObjectMapper objectMapper) {
        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
        objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
        objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
        objectMapper.registerModule(customAttributeModule());
    }

    private static SimpleModule customAttributeModule() {
        final SimpleModule customAttributeModule = new SimpleModule(
            "IntercomClientModule",
            new Version(1, 0, 0, null, "", "")
        );
        customAttributeModule.addDeserializer(CustomAttribute.class, new CustomAttributeDeserializer());
        customAttributeModule.addSerializer(CustomAttribute.class, new CustomAttributeSerializer());
        customAttributeModule.addDeserializer(Subscription.Topic.class, new TopicDeserializer());
        customAttributeModule.addSerializer(Subscription.Topic.class, new TopicSerializer());
        customAttributeModule.addSerializer(Counts.CountItem.class, new CountItemSerializer());
        customAttributeModule.addDeserializer(Counts.CountItem.class, new CountItemDeserializer());
        return customAttributeModule;
    }

    private static class Holder {
        private static final ObjectMapper INSTANCE = new ObjectMapper();
    }
}

@@ -386,31 +386,14 @@
     
-final ObjectMapper om =
+return
  Hol
@@ -414,53 +414,49 @@
     
+%7D%0A%0A
     
-configure(om);%0A        return om;
+private static class Holder %7B
 %0A    
-%7D%0A%0A
     
@@ -474,13 +474,51 @@
 tic 
-void 
+final ObjectMapper INSTANCE = new Holder().
 conf
@@ -523,16 +523,20 @@
 nfigure(
+new 
 ObjectMa
@@ -531,34 +531,78 @@
 new ObjectMapper
- o
+());%0A%0A        private ObjectMapper configure(O
 bjectMapper) %7B%0A 
@@ -596,16 +596,19 @@
 ctMapper
+ om
 ) %7B%0A    
@@ -607,36 +607,37 @@
 ) %7B%0A        
+    
-objectMapper
+return om
 .configure(S
@@ -684,25 +684,24 @@
 TAMPS, true)
-;
 %0A        obj
@@ -693,36 +693,36 @@
 ue)%0A        
-objectMapper
+            
 .configure(S
@@ -761,17 +761,16 @@
 T, true)
-;
 %0A       
@@ -766,36 +766,36 @@
 ue)%0A        
-objectMapper
+            
 .configure(S
@@ -850,33 +850,32 @@
 OSECONDS, false)
-;
 %0A        objectM
@@ -867,28 +867,28 @@
         
-objectMapper
+            
 .configu
@@ -956,17 +956,16 @@
 , false)
-;
 %0A       
@@ -965,28 +965,28 @@
         
-objectMapper
+            
 .registe
@@ -1019,27 +1019,35 @@
 ule());%0A    
-%7D%0A%0A
+    %7D%0A%0A    
     private 
@@ -1046,23 +1046,16 @@
 private 
-static 
 SimpleMo
@@ -1093,16 +1093,20 @@
         
+    
 final Si
@@ -1170,16 +1170,24 @@
         
+        
 %22Interco
@@ -1214,16 +1214,24 @@
         
+  
+      
 new Vers
@@ -1265,19 +1265,27 @@
         
-);%0A
+    );%0A    
         
@@ -1381,32 +1381,36 @@
 zer());%0A        
+ 
+   
 customAttributeM
@@ -1478,32 +1478,36 @@
 eSerializer());%0A
+    
         customAt
@@ -1588,32 +1588,36 @@
 zer());%0A        
+    
 customAttributeM
@@ -1686,32 +1686,36 @@
 zer());%0A        
+   
+ 
 customAttributeM
@@ -1778,32 +1778,36 @@
 mSerializer());%0A
+    
         customAt
@@ -1894,24 +1894,28 @@
 ));%0A        
+   
+ 
 return custo
@@ -1940,117 +1940,13 @@
     
-%7D%0A%0A
     
-private static class Holder %7B%0A        private static final ObjectMapper INSTANCE = new ObjectMapper();
+%7D
 %0A   

Configure Jackson ObjectMapper once