public ObjectNode toJson()

in ingestion-beam/src/main/java/com/mozilla/telemetry/amplitude/AmplitudeEvent.java [69:135]


  public ObjectNode toJson() throws JsonProcessingException {
    final ObjectNode json = Json.createObjectNode();
    json.put("user_id", getUserId());
    json.put("sample_id", getSampleId());

    final ObjectNode eventExtras = Json.createObjectNode();
    ObjectMapper objectMapper = new ObjectMapper();
    if (getEventExtras() == null || getEventExtras().equals("null")) {
      eventExtras.put("extra", objectMapper.readTree("{}"));
    } else {
      eventExtras.put("extra", objectMapper.readTree(getEventExtras()));
    }

    ObjectNode userProperties = Json.createObjectNode();
    userProperties.put("sample_id", getSampleId());

    if (getExperiments() != null) {
      userProperties.put("experiments",
          objectMapper.convertValue(getExperiments(), JsonNode.class));
    }

    json.put("event_properties", eventExtras);
    json.put("event_type", getEventType());
    userProperties.put("platform", getPlatform());
    json.put("platform", getPlatform());

    if (getAppVersion() != null && !getAppVersion().equals("null")) {
      json.put("app_version", getAppVersion());
      userProperties.put("version", getAppVersion());
    }

    if (getOsName() != null && !getOsName().equals("null")) {
      json.put("os_name", getOsName());
    }

    if (getOsVersion() != null && !getOsVersion().equals("null")) {
      json.put("os_version", getOsVersion());
    }

    if (getOsName() != null && !getOsName().equals("null") && getOsVersion() != null
        && !getOsVersion().equals("null")) {
      userProperties.put("os", getOsName() + " " + getOsVersion());
    }

    if (getCountry() != null && !getCountry().equals("null")) {
      json.put("country", getCountry());
      userProperties.put("country", getCountry());
    }

    if (getDeviceModel() != null && !getDeviceModel().equals("null")) {
      json.put("device_model", getDeviceModel());
      userProperties.put("device_model", getDeviceModel());
    }

    if (getDeviceManufacturer() != null && !getDeviceManufacturer().equals("null")) {
      json.put("device_manufacturer", getDeviceManufacturer());
      userProperties.put("device_manufacturer", getDeviceModel());
    }

    if (getLanguage() != null && !getLanguage().equals("null")) {
      userProperties.put("language", getLanguage());
    }

    json.put("user_properties", userProperties);

    return json;
  }