<commit_before>/*
    Copyright 2013-2014 Immutables.org authors

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.immutables.common.marshal;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.google.common.base.Throwables;
import java.io.IOException;
import java.io.StringWriter;
import org.immutables.common.marshal.internal.MarshalingSupport;

/**
 * Contains convenient methods for marshaling and unmarshaling documents annotated with
 * {@link org.immutables.value.Json.Marshaled} to and from standard textual JSON.
 * <p>
 * You can avoid using this class in favor of using Marshalers directly. But It's not always
 * possible if dynamic lookup is needed.
 */
public final class Marshaling {
  private Marshaling() {}

  private static final JsonFactory JSON_FACTORY = new JsonFactory();

  /**
   * Marshal object to JSON. Output JSON string is pretty-printed.
   * @param object the object
   * @return JSON string
   */
  // safe to not care of in-memory resource closing, which will be handled by GC
  @SuppressWarnings("resource")
  public static String toJson(Object object) {
    Marshaler<Object> marshaler = marshalerFor(object.getClass());
    try {
      StringWriter writer = new StringWriter();
      JsonGenerator generator = JSON_FACTORY.createGenerator(writer);
      generator.useDefaultPrettyPrinter();
      marshaler.marshalInstance(generator, object);
      return writer.toString();
    } catch (IOException ex) {
      throw Throwables.propagate(ex);
    }<commit_msg>fix. that particular generator.close() was mandatory ;)<commit_after>/*
    Copyright 2013-2014 Immutables.org authors

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.immutables.common.marshal;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.google.common.base.Throwables;
import java.io.IOException;
import java.io.StringWriter;
import org.immutables.common.marshal.internal.MarshalingSupport;

/**
 * Contains convenient methods for marshaling and unmarshaling documents annotated with
 * {@link org.immutables.value.Json.Marshaled} to and from standard textual JSON.
 * <p>
 * You can avoid using this class in favor of using Marshalers directly. But It's not always
 * possible if dynamic lookup is needed.
 */
public final class Marshaling {
  private Marshaling() {}

  private static final JsonFactory JSON_FACTORY = new JsonFactory();

  /**
   * Marshal object to JSON. Output JSON string is pretty-printed.
   * @param object the object
   * @return JSON string
   */
  // safe to not care of in-memory resource closing, which will be handled by GC
  @SuppressWarnings("resource")
  public static String toJson(Object object) {
    Marshaler<Object> marshaler = marshalerFor(object.getClass());
    try {
      StringWriter writer = new StringWriter();
      JsonGenerator generator = JSON_FACTORY.createGenerator(writer);
      generator.useDefaultPrettyPrinter();
      marshaler.marshalInstance(generator, object);
      generator.close();
      return writer.toString();
    } catch (IOException ex) {
      throw Throwables.propagate(ex);
    }
{'fraction_non_alphanumeric': 0.0799442249593307, 'fraction_numerical': 0.005577504066930049, 'mean_word_length': 3.952819332566168, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6740161', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1107, 'n_words': 427}