<commit_before>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);
  }
}<commit_msg>MyriaJsonMapperProvider: add ObjectMapper factory method<commit_after>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) {
      commonMapper = newMapper();
    }
    super.setMapper(commonMapper);
  }

  /**
   * Create the standard Myria custom ObjectMapper.
   * 
   * @return the standard Myria custom ObjectMapper.
   */
  public static ObjectMapper newMapper() {
    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);

    return mapper;
  }
}
{'fraction_non_alphanumeric': 0.08745141588006664, 'fraction_numerical': 0.0, 'mean_word_length': 4.206647398843931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4246831', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1032, 'n_words': 262}