001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package dev.metaschema.databind.model.info; 007 008import java.io.IOException; 009import java.util.List; 010import java.util.Map; 011 012import edu.umd.cs.findbugs.annotations.NonNull; 013 014/** 015 * Handler interface for writing model instance collections during 016 * serialization. 017 * <p> 018 * This interface provides methods for iterating over collection items and 019 * writing them to an output stream. 020 * 021 * @param <ITEM> 022 * the Java type of items being written 023 */ 024public interface IModelInstanceWriteHandler<ITEM> { 025 /** 026 * Write a singleton item. 027 * 028 * @param item 029 * the item to write 030 * @throws IOException 031 * if an error occurred while writing the output 032 */ 033 default void writeSingleton(@NonNull ITEM item) throws IOException { 034 writeItem(item); 035 } 036 037 /** 038 * Write items from a list collection. 039 * 040 * @param items 041 * the list of items to write 042 * @throws IOException 043 * if an error occurred while writing the output 044 */ 045 void writeList(@NonNull List<ITEM> items) throws IOException; 046 047 /** 048 * Write items from a map collection. 049 * 050 * @param items 051 * the map of items to write, keyed by JSON key flag value 052 * @throws IOException 053 * if an error occurred while writing the output 054 */ 055 void writeMap(@NonNull Map<String, ITEM> items) throws IOException; 056 057 /** 058 * Write the next item in the collection of items represented by the instance. 059 * 060 * @param item 061 * the item Java object to write 062 * @throws IOException 063 * if an error occurred while parsing the input 064 */ 065 void writeItem(@NonNull ITEM item) throws IOException; 066}