From f3c10ae97b54387a2f6196e34c4cb0c3feb12848 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:33:52 +0100 Subject: [PATCH] Polish JsonStream --- .../buildpack/platform/json/JsonStream.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java index 87dd8ecbcb9..e14964604d7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java @@ -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"); * you may not use this file except in compliance with the License. @@ -64,13 +64,14 @@ public class JsonStream { */ public void get(InputStream content, Class type, Consumer consumer) throws IOException { JsonFactory jsonFactory = this.objectMapper.getFactory(); - JsonParser parser = jsonFactory.createParser(content); - while (!parser.isClosed()) { - JsonToken token = parser.nextToken(); - if (token != null && token != JsonToken.END_OBJECT) { - T node = read(parser, type); - if (node != null) { - consumer.accept(node); + try (JsonParser parser = jsonFactory.createParser(content)) { + while (!parser.isClosed()) { + JsonToken token = parser.nextToken(); + if (token != null && token != JsonToken.END_OBJECT) { + T node = read(parser, type); + if (node != null) { + consumer.accept(node); + } } } }