Skip to content

Package: JsonGenerator

JsonGenerator

Coverage

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