/**
   * Creates a Jackson object mapper based on a media type. It supports JSON, JSON Smile, XML, YAML
   * and CSV.
   *
   * @return The Jackson object mapper.
   */
  protected ObjectMapper createObjectMapper() {
    ObjectMapper result = null;

    if (MediaType.APPLICATION_JSON.isCompatible(getMediaType())) {
      JsonFactory jsonFactory = new JsonFactory();
      jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
      result = new ObjectMapper(jsonFactory);
    } else if (MediaType.APPLICATION_JSON_SMILE.isCompatible(getMediaType())) {
      SmileFactory smileFactory = new SmileFactory();
      smileFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
      result = new ObjectMapper(smileFactory);
    } else if (MediaType.APPLICATION_XML.isCompatible(getMediaType())
        || MediaType.TEXT_XML.isCompatible(getMediaType())) {
      XmlFactory xmlFactory = new XmlFactory();
      xmlFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
      result = new XmlMapper(xmlFactory);
    } else if (MediaType.APPLICATION_YAML.isCompatible(getMediaType())) {
      YAMLFactory yamlFactory = new YAMLFactory();
      yamlFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
      result = new ObjectMapper(yamlFactory);
    } else if (MediaType.TEXT_CSV.isCompatible(getMediaType())) {
      CsvFactory csvFactory = new CsvFactory();
      csvFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
      result = new CsvMapper(csvFactory);
    } else {
      JsonFactory jsonFactory = new JsonFactory();
      jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
      result = new ObjectMapper(jsonFactory);
    }

    return result;
  }
  /**
   * Update / Validate existing OpenSearch
   *
   * @param representation OpenSearch configuration
   * @param variant client preferred media type
   * @return Representation
   */
  @Post
  public Representation newOpensearch(Representation representation, Variant variant) {
    if (representation == null) {
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST, "OPENSEARCH_REPRESENTATION_REQUIRED");
    }
    try {
      Opensearch osearchInput = null;
      if (MediaType.APPLICATION_XML.isCompatible(representation.getMediaType())) {
        // Parse the XML representation to get the bean
        osearchInput = new XstreamRepresentation<Opensearch>(representation).getObject();

      } else if (MediaType.APPLICATION_JSON.isCompatible(representation.getMediaType())) {
        // Parse the JSON representation to get the bean
        osearchInput =
            new JacksonRepresentation<Opensearch>(representation, Opensearch.class).getObject();
      }

      // Business service
      osearchInput.setStatus("INACTIVE");
      Opensearch osearchOutput = getStore().create(osearchInput);

      // Response
      Response response = new Response(true, osearchOutput, Opensearch.class, "opensearch");
      return getRepresentation(response, variant);

    } catch (ResourceException e) {
      getLogger().log(Level.INFO, null, e);
      throw e;
    } catch (Exception e) {
      getLogger().log(Level.SEVERE, null, e);
      throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
    }
  }