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   * Return the current path.
052   */
053  String path();
054
055  /**
056   * Set the current property names.
057   */
058  void names(PropertyNames names);
059
060  /**
061   * Set the next property name to write by position.
062   */
063  void name(int position);
064
065  /**
066   * Set the next property name to write.
067   * <p>
068   * This is generally less efficient than using {@link JsonWriter#names(PropertyNames)} and {@link JsonWriter#name(int)}.
069   */
070  void name(String name);
071
072  /**
073   * Write array begin.
074   */
075  void beginArray();
076
077  /**
078   * Write array end.
079   */
080  void endArray();
081
082  /**
083   * Write empty array.
084   */
085  void emptyArray();
086
087  /**
088   * Write object begin.
089   */
090  void beginObject();
091
092  /**
093   * Write object end.
094   */
095  void endObject();
096
097  /**
098   * Write null value.
099   */
100  void nullValue();
101
102  /**
103   * Write a string value.
104   */
105  void value(String value);
106
107  /**
108   * Write a boolean value.
109   */
110  void value(boolean value);
111
112  /**
113   * Write an int value.
114   */
115  void value(int value);
116
117  /**
118   * Write a long value.
119   */
120  void value(long value);
121
122  /**
123   * Write a double value.
124   */
125  void value(double value);
126
127  /**
128   * Write a Boolean value.
129   */
130  void value(Boolean value);
131
132  /**
133   * Write an Integer value.
134   */
135  void value(Integer value);
136
137  /**
138   * Write a Long value.
139   */
140  void value(Long value);
141
142  /**
143   * Write a Double value.
144   */
145  void value(Double value);
146
147  /**
148   * Write a BigDecimal value.
149   */
150  void value(BigDecimal value);
151
152  /**
153   * Write a BigInteger value.
154   */
155  void value(BigInteger value);
156
157  /**
158   * Write a value that could be any value.
159   */
160  void jsonValue(Object value);
161
162  /**
163   * Flush the writer.
164   */
165  void flush();
166
167  /**
168   * Close the writer.
169   */
170  void close();
171
172}