// Path: json-unit-core/src/main/java/net/javacrumbs/jsonunit/core/internal/Utils.java
// static void closeQuietly(final Reader resourceReader) {
//     if (resourceReader != null) {
//         try {
//             resourceReader.close();
//         } catch (IOException ignored) {
//         }
//     }
// }


import static net.javacrumbs.jsonunit.core.internal.Utils.closeQuietly;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import java.io.Reader;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map;
/**
 * Copyright 2009-2019 the original author or 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 net.javacrumbs.jsonunit.core.internal;





/**
 * Deserializes node using Gson
 */
class GsonNodeFactory extends AbstractNodeFactory {
    private final Gson gson = new Gson();

    @Override
    protected Node doConvertValue(Object source) {
        if (source instanceof JsonElement) {
            return newNode((JsonElement) source);
        } else {
            return newNode(gson.toJsonTree(source));
        }
    }

    @Override
    protected Node nullNode() {
        return newNode(JsonNull.INSTANCE);
    }

    @Override
    protected Node readValue(Reader value, String label, boolean lenient) {
        // GSON is always lenient :-(
        try {
            return newNode(JsonParser.parseReader(value));
        } catch (JsonIOException | JsonSyntaxException e) {
            throw newParseException(label, value, e);
        } finally {
// Path: json-unit-core/src/main/java/net/javacrumbs/jsonunit/core/internal/Utils.java
// static void closeQuietly(final Reader resourceReader) {
//     if (resourceReader != null) {
//         try {
//             resourceReader.close();
//         } catch (IOException ignored) {
//         }
//     }
// }


// Path: json-unit-core/src/main/java/net/javacrumbs/jsonunit/core/internal/GsonNodeFactory.java
import static net.javacrumbs.jsonunit.core.internal.Utils.closeQuietly;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import java.io.Reader;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map;

/**
 * Copyright 2009-2019 the original author or 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 net.javacrumbs.jsonunit.core.internal;





/**
 * Deserializes node using Gson
 */
class GsonNodeFactory extends AbstractNodeFactory {
    private final Gson gson = new Gson();

    @Override
    protected Node doConvertValue(Object source) {
        if (source instanceof JsonElement) {
            return newNode((JsonElement) source);
        } else {
            return newNode(gson.toJsonTree(source));
        }
    }

    @Override
    protected Node nullNode() {
        return newNode(JsonNull.INSTANCE);
    }

    @Override
    protected Node readValue(Reader value, String label, boolean lenient) {
        // GSON is always lenient :-(
        try {
            return newNode(JsonParser.parseReader(value));
        } catch (JsonIOException | JsonSyntaxException e) {
            throw newParseException(label, value, e);
        } finally {
            closeQuietly(value);