Skip to content

Commit

Permalink
Merge pull request #9879 from IQSS/9315-jsontry
Browse files Browse the repository at this point in the history
use try with resources in JsonUtil
  • Loading branch information
kcondon authored Sep 11, 2023
2 parents 6fee8e5 + 069bb91 commit 2c6afef
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 2c6afef

Please sign in to comment.