Skip to content

Commit f3c10ae

Browse files
committed
Polish JsonStream
1 parent 1f41179 commit f3c10ae

File tree

1 file changed

+9
-8
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json

1 file changed

+9
-8
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,13 +64,14 @@ public void get(InputStream content, Consumer<ObjectNode> consumer) throws IOExc
6464
*/
6565
public <T> void get(InputStream content, Class<T> type, Consumer<T> consumer) throws IOException {
6666
JsonFactory jsonFactory = this.objectMapper.getFactory();
67-
JsonParser parser = jsonFactory.createParser(content);
68-
while (!parser.isClosed()) {
69-
JsonToken token = parser.nextToken();
70-
if (token != null && token != JsonToken.END_OBJECT) {
71-
T node = read(parser, type);
72-
if (node != null) {
73-
consumer.accept(node);
67+
try (JsonParser parser = jsonFactory.createParser(content)) {
68+
while (!parser.isClosed()) {
69+
JsonToken token = parser.nextToken();
70+
if (token != null && token != JsonToken.END_OBJECT) {
71+
T node = read(parser, type);
72+
if (node != null) {
73+
consumer.accept(node);
74+
}
7475
}
7576
}
7677
}

0 commit comments

Comments
 (0)