@@ -69,9 +69,13 @@ public interface JsonType<T> extends JsonView<T> {
69
69
JsonType <List <T >> list ();
70
70
71
71
/**
72
- * Return the stream type for this JsonType .
72
+ * Prefer use of {@link JsonType# stream(JsonReader)} rather than using this stream type directly .
73
73
* <p>
74
- * When using this Stream type use a try-with-resources block with the Stream
74
+ * Generally, we should not use this type directly but instead create a {@link JsonReader}
75
+ * and use {@link JsonType#stream(JsonReader)} instead. Then we just use a try-with-resources on
76
+ * the JsonReader and can additionally specify {@link JsonReader#streamArray(boolean)} option.
77
+ * <p>
78
+ * When using this Stream type directly, use a try-with-resources block with the Stream
75
79
* to ensure that any underlying resources are closed.
76
80
*
77
81
* <pre>{@code
@@ -84,6 +88,9 @@ public interface JsonType<T> extends JsonView<T> {
84
88
* }
85
89
*
86
90
* }</pre>
91
+ *
92
+ * @return The stream type for this base JsonType.
93
+ * @see #stream(JsonReader)
87
94
*/
88
95
JsonType <Stream <T >> stream ();
89
96
@@ -142,12 +149,32 @@ public interface JsonType<T> extends JsonView<T> {
142
149
* JsonType<MyBean> type = jsonb.type(MyBean.class);
143
150
*
144
151
* try (JsonReader reader = jsonb.reader(content)) {
145
-
152
+ *
146
153
* Stream<MyBean> asStream = type.stream(reader);
147
154
* ...
148
155
* }
149
156
*
150
157
* }</pre>
158
+ *
159
+ * <h3>When using Jackson</h3>
160
+ * <p>
161
+ * When using Jackson-core as the underlying parser we should explicitly state that the content is either
162
+ * an ARRAY (with '[' and ']' tokens or not (x-json-stream new line delimited, there are no '[' and ']' tokens).
163
+ * <p>
164
+ * When using the builtin avaje-jsonb parser, it automatically detects and handles both cases (with or without the
165
+ * '[' and ']' tokens). With the Jackson-core parser we need to explicitly state if we are processing
166
+ *
167
+ * <pre>{@code
168
+ *
169
+ * JsonType<MyBean> type = jsonb.type(MyBean.class);
170
+ *
171
+ * try (JsonReader reader = jsonb.reader(content)) {
172
+ * // when the content contains the ARRAY '[', ']' tokens set streamArray(true)
173
+ * Stream<MyBean> asStream = type.stream(reader.streamArray(true));
174
+ * ...
175
+ * }
176
+ *
177
+ * }</pre>
151
178
*/
152
179
Stream <T > stream (JsonReader reader );
153
180
0 commit comments