Skip to content

Commit

Permalink
use try with resources in JsonUtil #9315
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Sep 5, 2023
1 parent 9499d75 commit de71e6c
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.logging.Logger;
import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonReader;
import jakarta.json.JsonWriter;
import jakarta.json.JsonWriterFactory;
import jakarta.json.stream.JsonGenerator;
Expand Down Expand Up @@ -60,13 +61,17 @@ public static String prettyPrint(jakarta.json.JsonObject jsonObject) {

public static jakarta.json.JsonObject getJsonObject(String serializedJson) {
try (StringReader rdr = new StringReader(serializedJson)) {
return Json.createReader(rdr).readObject();
try (JsonReader jsonReader = Json.createReader(rdr)) {
return jsonReader.readObject();
}
}
}

public static jakarta.json.JsonArray getJsonArray(String serializedJson) {
try (StringReader rdr = new StringReader(serializedJson)) {
return Json.createReader(rdr).readArray();
try (JsonReader jsonReader = Json.createReader(rdr)) {
return jsonReader.readArray();
}
}
}
}

0 comments on commit de71e6c

Please sign in to comment.