mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish JsonStream
This commit is contained in:
parent
1f41179a88
commit
f3c10ae97b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -64,13 +64,14 @@ public class JsonStream {
|
|||||||
*/
|
*/
|
||||||
public <T> void get(InputStream content, Class<T> type, Consumer<T> consumer) throws IOException {
|
public <T> void get(InputStream content, Class<T> type, Consumer<T> consumer) throws IOException {
|
||||||
JsonFactory jsonFactory = this.objectMapper.getFactory();
|
JsonFactory jsonFactory = this.objectMapper.getFactory();
|
||||||
JsonParser parser = jsonFactory.createParser(content);
|
try (JsonParser parser = jsonFactory.createParser(content)) {
|
||||||
while (!parser.isClosed()) {
|
while (!parser.isClosed()) {
|
||||||
JsonToken token = parser.nextToken();
|
JsonToken token = parser.nextToken();
|
||||||
if (token != null && token != JsonToken.END_OBJECT) {
|
if (token != null && token != JsonToken.END_OBJECT) {
|
||||||
T node = read(parser, type);
|
T node = read(parser, type);
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
consumer.accept(node);
|
consumer.accept(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user