@Test public void getEventsFromNotValidJson() throws Exception { final List<Event> events = jsonHandler .getEvents("[{\"field1\":\"value1\"},{\"field2\":}]", ImmutableMap.<String, String>builder().build()); assertThat(events).isEmpty(); }
@Override public List<Event> getEvents(String body, Map<String, String> headers) { List<Event> events = new ArrayList<Event>(0); ObjectMapper mapper = new ObjectMapper(); try { JsonNode jsonNode = mapper.readTree(body); if (jsonNode.isObject()) { events.add(buildSingleEvent(headers, findValue(jsonNode, path))); } if (jsonNode.isArray()) { final Iterator<JsonNode> elements = jsonNode.getElements(); JsonNode element; while (elements.hasNext()) { element = elements.next(); events.add(buildSingleEvent(headers, findValue(element, path))); } } } catch (Exception e) { LOG.warn("An error ocurred while response parsing. Then content is not valid: " + body); } return events; }
JsonRestSourceHandler implements RestSourceHandler { @Override public List<Event> getEvents(String body, Map<String, String> headers) { List<Event> events = new ArrayList<Event>(0); ObjectMapper mapper = new ObjectMapper(); try { JsonNode jsonNode = mapper.readTree(body); if (jsonNode.isObject()) { events.add(buildSingleEvent(headers, findValue(jsonNode, path))); } if (jsonNode.isArray()) { final Iterator<JsonNode> elements = jsonNode.getElements(); JsonNode element; while (elements.hasNext()) { element = elements.next(); events.add(buildSingleEvent(headers, findValue(element, path))); } } } catch (Exception e) { LOG.warn("An error ocurred while response parsing. Then content is not valid: " + body); } return events; } }
JsonRestSourceHandler implements RestSourceHandler { @Override public List<Event> getEvents(String body, Map<String, String> headers) { List<Event> events = new ArrayList<Event>(0); ObjectMapper mapper = new ObjectMapper(); try { JsonNode jsonNode = mapper.readTree(body); if (jsonNode.isObject()) { events.add(buildSingleEvent(headers, findValue(jsonNode, path))); } if (jsonNode.isArray()) { final Iterator<JsonNode> elements = jsonNode.getElements(); JsonNode element; while (elements.hasNext()) { element = elements.next(); events.add(buildSingleEvent(headers, findValue(element, path))); } } } catch (Exception e) { LOG.warn("An error ocurred while response parsing. Then content is not valid: " + body); } return events; } JsonRestSourceHandler(); }
JsonRestSourceHandler implements RestSourceHandler { @Override public List<Event> getEvents(String body, Map<String, String> headers) { List<Event> events = new ArrayList<Event>(0); ObjectMapper mapper = new ObjectMapper(); try { JsonNode jsonNode = mapper.readTree(body); if (jsonNode.isObject()) { events.add(buildSingleEvent(headers, findValue(jsonNode, path))); } if (jsonNode.isArray()) { final Iterator<JsonNode> elements = jsonNode.getElements(); JsonNode element; while (elements.hasNext()) { element = elements.next(); events.add(buildSingleEvent(headers, findValue(element, path))); } } } catch (Exception e) { LOG.warn("An error ocurred while response parsing. Then content is not valid: " + body); } return events; } JsonRestSourceHandler(); @Override List<Event> getEvents(String body, Map<String, String> headers); @Override void configure(Context context); }
JsonRestSourceHandler implements RestSourceHandler { @Override public List<Event> getEvents(String body, Map<String, String> headers) { List<Event> events = new ArrayList<Event>(0); ObjectMapper mapper = new ObjectMapper(); try { JsonNode jsonNode = mapper.readTree(body); if (jsonNode.isObject()) { events.add(buildSingleEvent(headers, findValue(jsonNode, path))); } if (jsonNode.isArray()) { final Iterator<JsonNode> elements = jsonNode.getElements(); JsonNode element; while (elements.hasNext()) { element = elements.next(); events.add(buildSingleEvent(headers, findValue(element, path))); } } } catch (Exception e) { LOG.warn("An error ocurred while response parsing. Then content is not valid: " + body); } return events; } JsonRestSourceHandler(); @Override List<Event> getEvents(String body, Map<String, String> headers); @Override void configure(Context context);  }