Given you start with mapping.get("servers").getAsJsonArray()
, if you have access to Guava Streams
, you can do the below one-liner:
List<String> servers = Streams.stream(jsonArray.iterator())
.map(je -> je.getAsString())
.collect(Collectors.toList());
Note StreamSupport
won't be able to work on JsonElement
type, so it is insufficient.