package edu.washington.escience.myria.api;

import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;

/**
 * This class generates a custom JSON {@link ObjectMapper} that will properly convert Java CamelCase field names to JSON
 * lower_case_with_underscores field names.
 * 
 * @author dhalperi
 * 
 */
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class MyriaJsonMapperProvider extends JacksonJaxbJsonProvider {
  /** Only create this object once, and share it among instances. */
  private static ObjectMapper commonMapper = null;

  /** Get (or create) the custom ObjectMapper and then set it in the parent. */
  public MyriaJsonMapperProvider() {
    if (commonMapper == null) {
      ObjectMapper mapper = new ObjectMapper();

      /*
       * These are recommended by Swagger devs but I want to hold and see what we want. Leaving the code here for future
       * use.
       */
      // mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
      // mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
      // mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
      // mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

      /* Use the Web's property naming strategy. */
      mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);

      commonMapper = mapper;
    }
    super.setMapper(commonMapper);
  }
}
@@ -907,16 +907,260 @@
 ll) %7B%0A  
+    commonMapper = newMapper();%0A    %7D%0A    super.setMapper(commonMapper);%0A  %7D%0A%0A  /**%0A   * Create the standard Myria custom ObjectMapper.%0A   * %0A   * @return the standard Myria custom ObjectMapper.%0A   */%0A  public static ObjectMapper newMapper() %7B%0A
     Obje
@@ -1206,15 +1206,11 @@
     
-  
 /*%0A
-  
     
@@ -1329,18 +1329,16 @@
 re%0A     
-  
 * use.%0A 
@@ -1341,23 +1341,19 @@
 e.%0A     
- 
- 
 */%0A
-  
     // m
@@ -1415,18 +1415,16 @@
 _NULL);%0A
-  
     // m
@@ -1489,26 +1489,24 @@
 FAULT);%0A    
-  
 // mapper.co
@@ -1569,18 +1569,16 @@
 false);%0A
-  
     // m
@@ -1657,18 +1657,16 @@
 );%0A%0A    
- 
- 
 /* Use t
@@ -1703,18 +1703,16 @@
 egy. */%0A
-  
     mapp
@@ -1816,72 +1816,21 @@
     
-  commonMapper = mapper;%0A    %7D%0A    super.setMapper(commonM
+return m
 apper
-)
 ;%0A  

add ObjectMapper factory method