// Path: json-unit-core/src/main/java/net/javacrumbs/jsonunit/providers/Jackson2ObjectMapperProvider.java
// public interface Jackson2ObjectMapperProvider {
//     /**
//      * Provides ObjectMapper
//      * @param lenient Lenient parsing is used for parsing the expected JSON value
//      * @return customized ObjectMapper.
//      */
//     ObjectMapper getObjectMapper(boolean lenient);
// }
// 
// 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 com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.NullNode;
import net.javacrumbs.jsonunit.providers.Jackson2ObjectMapperProvider;
import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import static net.javacrumbs.jsonunit.core.internal.Utils.closeQuietly;
/**
 * 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 Jackson 2
 */
class Jackson2NodeFactory extends AbstractNodeFactory {
    private final ServiceLoader<Jackson2ObjectMapperProvider> serviceLoader = ServiceLoader.load(Jackson2ObjectMapperProvider.class);

    @Override
    protected Node doConvertValue(Object source) {
        if (source instanceof JsonNode) {
            return newNode((JsonNode) source);
        } else {
            return newNode(getMapper(false).convertValue(source, JsonNode.class));
        }
    }

    @Override
    protected Node nullNode() {
        return newNode(NullNode.getInstance());
    }

    @Override
    protected Node readValue(Reader value, String label, boolean lenient) {
        try {
            return newNode(getMapper(lenient).readTree(value));
        } catch (IOException e) {
            throw newParseException(label, value, e);
        } finally {
// Path: json-unit-core/src/main/java/net/javacrumbs/jsonunit/providers/Jackson2ObjectMapperProvider.java
// public interface Jackson2ObjectMapperProvider {
//     /**
//      * Provides ObjectMapper
//      * @param lenient Lenient parsing is used for parsing the expected JSON value
//      * @return customized ObjectMapper.
//      */
//     ObjectMapper getObjectMapper(boolean lenient);
// }
// 
// 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/Jackson2NodeFactory.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.NullNode;
import net.javacrumbs.jsonunit.providers.Jackson2ObjectMapperProvider;
import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import static net.javacrumbs.jsonunit.core.internal.Utils.closeQuietly;

/**
 * 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 Jackson 2
 */
class Jackson2NodeFactory extends AbstractNodeFactory {
    private final ServiceLoader<Jackson2ObjectMapperProvider> serviceLoader = ServiceLoader.load(Jackson2ObjectMapperProvider.class);

    @Override
    protected Node doConvertValue(Object source) {
        if (source instanceof JsonNode) {
            return newNode((JsonNode) source);
        } else {
            return newNode(getMapper(false).convertValue(source, JsonNode.class));
        }
    }

    @Override
    protected Node nullNode() {
        return newNode(NullNode.getInstance());
    }

    @Override
    protected Node readValue(Reader value, String label, boolean lenient) {
        try {
            return newNode(getMapper(lenient).readTree(value));
        } catch (IOException e) {
            throw newParseException(label, value, e);
        } finally {
            closeQuietly(value);