001package io.ebean.text.json;
002
003import com.fasterxml.jackson.core.JsonGenerator;
004
005import java.io.InputStream;
006import java.math.BigDecimal;
007
008/**
009 * Wraps an underlying JsonGenerator taking into account null suppression and exposing isIncludeEmpty() etc.
010 */
011public interface JsonWriter {
012
013  /**
014   * Return the Jackson core JsonGenerator.
015   */
016  JsonGenerator gen();
017
018  /**
019   * Return true if null values should be included in JSON output.
020   */
021  boolean isIncludeNull();
022
023  /**
024   * Return true if empty collections should be included in the JSON output.
025   */
026  boolean isIncludeEmpty();
027
028  /**
029   * Write a field name followed by object start.
030   */
031  void writeStartObject(String key);
032
033  /**
034   * Write a object start.
035   */
036  void writeStartObject();
037
038  /**
039   * Write a object end.
040   */
041  void writeEndObject();
042
043  /**
044   * Write a field name followed by array start.
045   */
046  void writeStartArray(String key);
047
048  /**
049   * Write a array start.
050   */
051  void writeStartArray();
052
053  /**
054   * Write a array end.
055   */
056  void writeEndArray();
057
058  /**
059   * Write the field name.
060   */
061  void writeFieldName(String name);
062
063  /**
064   * Write a null value taking into account null value suppression.
065   */
066  void writeNullField(String name);
067
068  /**
069   * Write a number field.
070   */
071  void writeNumberField(String name, int value);
072
073  /**
074   * Write a number field.
075   */
076  void writeNumberField(String name, short value);
077
078  /**
079   * Write a number field.
080   */
081  void writeNumberField(String name, long value);
082
083  /**
084   * Write a number field.
085   */
086  void writeNumberField(String name, double value);
087
088  /**
089   * Write a number field.
090   */
091  void writeNumberField(String name, float value);
092
093  /**
094   * Write a number field.
095   */
096  void writeNumberField(String name, BigDecimal value);
097
098  /**
099   * Write a sting field.
100   */
101  void writeStringField(String name, String value);
102
103  /**
104   * Write a binary field.
105   */
106  void writeBinary(InputStream is, int length);
107
108  /**
109   * Write a binary field.
110   */
111  void writeBinaryField(String name, byte[] value);
112
113  /**
114   * Write a boolean field.
115   */
116  void writeBooleanField(String name, boolean value);
117
118  /**
119   * Write a boolean value (typically inside a list).
120   */
121  void writeBoolean(boolean value);
122
123  /**
124   * Write a string value (typically inside a list).
125   */
126  void writeString(String value);
127
128  /**
129   * Write a int value (typically inside a list).
130   */
131  void writeNumber(int value);
132
133  /**
134   * Write a long value (typically inside a list).
135   */
136  void writeNumber(long value);
137
138  /**
139   * Write a double value.
140   */
141  void writeNumber(double value);
142
143  /**
144   * Write a BigDecimal value (typically inside a list).
145   */
146  void writeNumber(BigDecimal value);
147
148  /**
149   * Write a null value.
150   */
151  void writeNull();
152
153  /**
154   * Method that will force generator to copy
155   * input text verbatim with <b>no</b> modifications (including
156   * that no escaping is done and no separators are added even
157   * if context [array, object] would otherwise require such).
158   * If such separators are desired, use
159   * {@link #writeRawValue(String)} instead.
160   */
161  void writeRaw(String text);
162
163  /**
164   * Method that will force generator to copy
165   * input text verbatim without any modifications, but assuming
166   * it must constitute a single legal JSON value (number, string,
167   * boolean, null, Array or List). Assuming this, proper separators
168   * are added if and as needed (comma or colon), and generator
169   * state updated to reflect this.
170   */
171  void writeRawValue(String text);
172}