Skip to content

Package: JsonGenerator

JsonGenerator

Coverage

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jsonld.serialization;
16:
17: import java.io.IOException;
18:
19: /**
20: * Represents interface to the underlying JAXB implementation, which handles the actual value serialization.
21: */
22: public interface JsonGenerator {
23:
24: /**
25: * Writes a field name (JSON string surrounded by double quotes).
26: * <p>
27: * Can be used only in an object, when a field name is expected.
28: *
29: * @param name Field name to write
30: * @throws IOException When JSON writing error occurs
31: */
32: void writeFieldName(String name) throws IOException;
33:
34: /**
35: * Writes a starting marker of a JSON object value (the '{' character).
36: * <p>
37: * Can be used anywhere except when a field name is expected.
38: *
39: * @throws IOException When JSON writing error occurs
40: */
41: void writeObjectStart() throws IOException;
42:
43: /**
44: * Writes a closing marker of a JSON object value (the '}' character).
45: * <p>
46: * Can be used for closing objects either after a complete value or an object opening marker.
47: *
48: * @throws IOException When JSON writing error occurs
49: */
50: void writeObjectEnd() throws IOException;
51:
52: /**
53: * Writes an opening marker of a JSON array value (the '[' character).
54: * <p>
55: * Can be used anywhere except when a field name is expected.
56: *
57: * @throws IOException When JSON writing error occurs
58: */
59: void writeArrayStart() throws IOException;
60:
61: /**
62: * Writes a closing marker of a JSON array value(the ']' character).
63: * <p>
64: * Can be used when the innermost structured type is array.
65: *
66: * @throws IOException When JSON writing error occurs
67: */
68: void writeArrayEnd() throws IOException;
69:
70: /**
71: * Outputs the given numeric value as a JSON number.
72: *
73: * @param number Number to write
74: * @throws IOException When JSON writing error occurs
75: */
76: void writeNumber(Number number) throws IOException;
77:
78: /**
79: * Outputs the given boolean value as a JSON boolean.
80: *
81: * @param value Value to write
82: * @throws IOException When JSON writing error occurs
83: */
84: void writeBoolean(boolean value) throws IOException;
85:
86: /**
87: * Outputs JSON literal {@code null} value.
88: * <p>
89: * This is usually not used, because {@code null} values are by default omitted by the serialization. But this can
90: * be configurable.
91: *
92: * @throws IOException When JSON writing error occurs
93: */
94: void writeNull() throws IOException;
95:
96: /**
97: * Outputs a String value.
98: * <p>
99: * Escaping will be done by the underlying implementation.
100: *
101: * @param text Text to write
102: * @throws IOException When JSON writing error occurs
103: */
104: void writeString(String text) throws IOException;
105: }