class CveReader2 implements ObjectFetcher<String, Cve> {

  private static final Cve buildFromJson(String _id, String _json) throws ParseException {
    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
    final Cve cve = new Cve();
    cve.setId(_id);

    final Configuration conf = Configuration.defaultConfiguration();
    // conf.addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
    final Object document = conf.jsonProvider().parse(_json);

    // Take first english description
    final JSONArray descriptions =
        JsonPath.read(document, "$.cve.description.description_data[?(@.lang=='en')].value");
    if (descriptions == null || descriptions.size() == 0) {
      log.warn("No english description found for CVE [" + _id + "]");
      cve.setSummary("Not available");
    } else {
      cve.setSummary(descriptions.get(0).toString());
    }

    final String published = JsonPath.read(document, "$.publishedDate");
    final Calendar publ = new GregorianCalendar();
    publ.setTime(format.parse(published));
    cve.setPublished(publ);

    final String modified = JsonPath.read(document, "$.lastModifiedDate");
    final Calendar modi = new GregorianCalendar();
    modi.setTime(format.parse(modified));
    cve.setModified(modi);

    String cvss3_version = null;
    Double cvss3_score = null;
    String cvss3_vector = null;
    try {
      cvss3_version = JsonPath.read(document, "$.impact.baseMetricV3.cvssV3.version");
      cvss3_score = JsonPath.read(document, "$.impact.baseMetricV3.cvssV3.baseScore");
      cvss3_vector = JsonPath.read(document, "$.impact.baseMetricV3.cvssV3.vectorString");
    } catch (Exception e) {
      log.warn(
          "Exception when reading CVSS v3 information for CVE [" + _id + "]: " + e.getMessage());
    }

    String cvss2_version = null;
    Double cvss2_score = null;
    String cvss2_vector = null;
    try {
      cvss2_version = JsonPath.read(document, "$.impact.baseMetricV2.cvssV2.version");
      cvss2_score = JsonPath.read(document, "$.impact.baseMetricV2.cvssV2.baseScore");
      cvss2_vector = JsonPath.read(document, "$.impact.baseMetricV2.cvssV2.vectorString");
    } catch (Exception e) {
      log.warn(
          "Exception when reading CVSS v2 information for CVE [" + _id + "]: " + e.getMessage());
    }

    if (cvss3_version != null && cvss3_score != null && cvss3_vector != null) {
      cve.setCvssScore(cvss3_score.floatValue());
      cve.setCvssVector(cvss3_vector);
      cve.setCvssVersion(cvss3_version);
    } else if (cvss2_version != null && cvss2_score != null && cvss2_vector != null) {
      cve.setCvssScore(cvss2_score.floatValue());
      cve.setCvssVector(cvss2_vector);
      cve.setCvssVersion(cvss2_version);
    }

    return cve;
  }

}