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