/**
   * 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;
  }
  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("Usage: java [input]");
      System.exit(1);
    }
    byte[] data = readAll(args[0]);

    JsonFactory f = new JsonFactory();
    boolean doIntern = true;

    f.configure(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES, doIntern);
    f.configure(JsonFactory.Feature.INTERN_FIELD_NAMES, doIntern);

    ObjectMapper m = new ObjectMapper();
    Object input1 = m.readValue(data, Object.class);
    JsonNode input2 = m.readTree(data);

    new ManualReadPerfUntypedStream()
        .testFromBytes(
            //            .testFromString(
            m, "JSON-as-Object", input1, Object.class, m, "JSON-as-Object2", input2, Object.class
            //               ,m, "JSON-as-Node", input2, JsonNode.class
            );
  }
Ejemplo n.º 3
0
 static {
   jsonFactory = new JsonFactory();
   jsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
   jsonFactory.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
   jsonXContent = new JsonXContent();
 }
Ejemplo n.º 4
0
 @Override
 protected ObjectMapper createInstance() throws Exception {
   JsonFactory jf = new JsonFactory();
   jf.configure(JsonFactory.Feature.INTERN_FIELD_NAMES, false);
   return configureObjectMapper(new ObjectMapper(jf));
 }