YamasJsonUtil { public static List<MetricsPacket.Builder> toMetricsPackets(String jsonString) { List<MetricsPacket.Builder> packets = new ArrayList<>(); try { JsonParser jp = new JsonFactory().createParser(jsonString); jp.setCodec(new ObjectMapper()); while (jp.nextToken() != null) { YamasJsonModel jsonModel = jp.readValueAs(YamasJsonModel.class); packets.add(toMetricsPacketBuilder(jsonModel)); } return packets; } catch (IOException e) { log.log(WARNING, "Could not create metrics packet from string:\n" + jsonString, e); return emptyList(); } }  static MetricsPacket.Builder toMetricsPacketBuilder(YamasJsonModel jsonModel); static YamasArrayJsonModel toYamasArray(Collection<MetricsPacket> metricsPackets); static YamasArrayJsonModel toYamasArray(Collection<MetricsPacket> metricsPackets, boolean addStatus); static List<MetricsPacket.Builder> toMetricsPackets(String jsonString);  }
@Test public void empty_json_string_yields_empty_packet_list() { List<MetricsPacket.Builder> builders = toMetricsPackets(""); assertTrue(builders.isEmpty()); }