001/* 002 * Copyright (C) 2014 Square, Inc. 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 */ 016package io.avaje.jsonb; 017 018import io.avaje.jsonb.spi.PropertyNames; 019 020import java.io.Closeable; 021import java.io.Flushable; 022import java.math.BigDecimal; 023 024/** 025 * Writes json content. 026 */ 027public interface JsonWriter extends Closeable, Flushable { 028 029 /** 030 * Set to serialise null values or not. 031 */ 032 void serializeNulls(boolean serializeNulls); 033 034 /** 035 * Return true if null values should be serialised. 036 */ 037 boolean serializeNulls(); 038 039 /** 040 * Set to serialise empty collections or not. 041 */ 042 void serializeEmpty(boolean serializeEmpty); 043 044 /** 045 * Return true if empty collections should be serialised. 046 */ 047 boolean serializeEmpty(); 048 049 /** 050 * Return the current path. 051 */ 052 String path(); 053 054 /** 055 * Set the current property names. 056 */ 057 void names(PropertyNames names); 058 059 /** 060 * Set the next property name to write by position. 061 */ 062 void name(int position); 063 064 /** 065 * Set the next property name to write. 066 * <p> 067 * This is generally less efficient than using {@link JsonWriter#names(PropertyNames)} and {@link JsonWriter#name(int)}. 068 */ 069 void name(String name); 070 071 /** 072 * Write array begin. 073 */ 074 void beginArray(); 075 076 /** 077 * Write array end. 078 */ 079 void endArray(); 080 081 /** 082 * Write empty array. 083 */ 084 void emptyArray(); 085 086 /** 087 * Write object begin. 088 */ 089 void beginObject(); 090 091 /** 092 * Write object end. 093 */ 094 void endObject(); 095 096 /** 097 * Write null value. 098 */ 099 void nullValue(); 100 101 /** 102 * Write a string value. 103 */ 104 void value(String value); 105 106 /** 107 * Write a boolean value. 108 */ 109 void value(boolean value); 110 111 /** 112 * Write an int value. 113 */ 114 void value(int value); 115 116 /** 117 * Write a long value. 118 */ 119 void value(long value); 120 121 /** 122 * Write a double value. 123 */ 124 void value(double value); 125 126 /** 127 * Write a Boolean value. 128 */ 129 void value(Boolean value); 130 131 /** 132 * Write an Integer value. 133 */ 134 void value(Integer value); 135 136 /** 137 * Write a Long value. 138 */ 139 void value(Long value); 140 141 /** 142 * Write a Double value. 143 */ 144 void value(Double value); 145 146 /** 147 * Write a BigDecimal value. 148 */ 149 void value(BigDecimal value); 150 151 /** 152 * Write a value that could be any value. 153 */ 154 void jsonValue(Object value); 155 156 /** 157 * Write raw encoded json value. 158 */ 159 void rawValue(String value); 160 161 /** 162 * Close the writer. 163 */ 164 void close(); 165 166 /** 167 * Flush the writer. 168 */ 169 void flush(); 170 171}