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.json; 018 019import java.lang.reflect.Type; 020 021import com.fasterxml.jackson.databind.ObjectMapper; 022 023import org.microbean.loader.jackson.InputStreamJacksonProvider; 024 025import org.microbean.invoke.CachingSupplier; 026 027/** 028 * An {@link InputStreamJacksonProvider} that reads JSON-formatted 029 * {@code application.json} classpath resources. 030 * 031 * @author <a href="https://about.me/lairdnelson" 032 * target="_parent">Laird Nelson</a> 033 * 034 * @see InputStreamJacksonProvider 035 */ 036public class JsonProvider extends InputStreamJacksonProvider { 037 038 039 /* 040 * Constructors. 041 */ 042 043 044 /** 045 * Creates a new {@link JsonProvider} that reads JSON-formatted 046 * {@code application.json} classpath resources. 047 * 048 * @see #JsonProvider(Type, String) 049 */ 050 public JsonProvider() { 051 this(null, "application.json"); 052 } 053 054 /** 055 * Creates a new {@link JsonProvider}. 056 * 057 * @param resourceName the name of the classpath resource to read 058 * from; must not be {@code null} 059 * 060 * @exception NullPointerException if {@code resourceName} is {@code 061 * null} 062 * 063 * @see #JsonProvider(Type, String) 064 */ 065 public JsonProvider(final String resourceName) { 066 this(null, resourceName); 067 } 068 069 /** 070 * Creates a new {@link JsonProvider}. 071 * 072 * @param lowerBound the {@linkplain #lowerBound() lower type bound} 073 * of this {@link JsonProvider}; may be {@code null} 074 * 075 * @param resourceName the name of the classpath resource to read 076 * from; must not be {@code null} 077 * 078 * @exception NullPointerException if {@code resourceName} is {@code 079 * null} 080 */ 081 public JsonProvider(final Type lowerBound, final String resourceName) { 082 super(lowerBound, new CachingSupplier<>(ObjectMapper::new), resourceName); 083 } 084 085}