001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2021–2022 microBean™.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
014 * implied.  See the License for the specific language governing
015 * permissions and limitations under the License.
016 */
017package org.microbean.loader.jackson.yaml;
018
019import java.lang.reflect.Type;
020
021import java.util.function.Supplier;
022
023import com.fasterxml.jackson.databind.ObjectMapper;
024
025import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
026
027import org.microbean.loader.jackson.InputStreamJacksonProvider;
028
029import org.microbean.invoke.CachingSupplier;
030
031/**
032 * An {@link InputStreamJacksonProvider} that reads YAML-formatted
033 * {@code application.yaml} classpath resources.
034 *
035 * @author <a href="https://about.me/lairdnelson"
036 * target="_parent">Laird Nelson</a>
037 *
038 * @see InputStreamJacksonProvider
039 */
040public class YamlProvider extends InputStreamJacksonProvider {
041
042
043  /*
044   * Constructors.
045   */
046
047
048  /**
049   * Creates a new {@link YamlProvider} that reads YAML-formatted
050   * {@code application.yaml} classpath resources.
051   *
052   * @see #YamlProvider(Type, String)
053   */
054  public YamlProvider() {
055    this(null, "application.yaml");
056  }
057
058  /**
059   * Creates a new {@link YamlProvider}.
060   *
061   * @param lowerBound the {@linkplain #lowerBound() lower type bound}
062   * of this {@link InputStreamJacksonProvider} implementation; may be
063   * {@code null}
064   *
065   * @param resourceName the name of the classpath resource to read
066   * from; must not be {@code null}
067   *
068   * @exception NullPointerException if {@code resourceName} is {@code
069   * null}
070   */
071  public YamlProvider(final Type lowerBound, final String resourceName) {
072    super(lowerBound, new CachingSupplier<>(YAMLMapper::new), resourceName);
073  }
074
075}