001/* 002 * Copyright 2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.item.json; 018 019import org.springframework.core.io.Resource; 020import org.springframework.lang.Nullable; 021 022/** 023 * Strategy interface for Json readers. Implementations are expected to use 024 * a streaming API in order to read Json objects one at a time. 025 * 026 * @param <T> type of the target object 027 * 028 * @author Mahmoud Ben Hassine 029 * @since 4.1 030 */ 031public interface JsonObjectReader<T> { 032 033 /** 034 * Open the Json resource for reading. 035 * @param resource the input resource 036 * @throws Exception if unable to open the resource 037 */ 038 default void open(Resource resource) throws Exception { 039 040 } 041 042 /** 043 * Read the next object in the Json resource if any. 044 * @return the next object or {@code null} if the resource is exhausted 045 * @throws Exception if unable to read the next object 046 */ 047 @Nullable 048 T read() throws Exception; 049 050 /** 051 * Close the input resource. 052 * @throws Exception if unable to close the input resource 053 */ 054 default void close() throws Exception { 055 056 } 057}