/** {@inheritDoc} */
  @Override
  public JSONObject fromPojo(ServiceConfiguration pojo) throws JSONException {
    JSONObject jsonObject = new JSONObject();

    if (pojo.getEnsureRunning() != null) {
      jsonObject.put(ENSURE_RUNNING.jsonKey(), pojo.getEnsureRunning().toString());
    }

    if (pojo.getEnabled() != null) {
      jsonObject.put(ENABLED.jsonKey(), pojo.getEnabled().toString());
    }

    if (!pojo.getFiles().isEmpty()) {
      JSONArray filesArray = new JSONArray(pojo.getFiles());
      jsonObject.put(FILES.jsonKey(), filesArray);
    }

    if (!pojo.getSources().isEmpty()) {
      JSONArray sourcesArray = new JSONArray(pojo.getSources());
      jsonObject.put(SOURCES.jsonKey(), sourcesArray);
    }

    if (!pojo.getCommands().isEmpty()) {
      JSONArray commandsArray = new JSONArray(pojo.getCommands());
      jsonObject.put(COMMANDS.jsonKey(), commandsArray);
    }

    if (!pojo.getPackages().isEmpty()) {
      JSONObject packageManagers = new JSONObject();

      for (Map.Entry<PackageManagerName, PackageDependencies> mapEntry :
          pojo.getPackages().entrySet()) {
        PackageManagerName packageManagerKey = mapEntry.getKey();
        PackageDependencies packageDependencies = mapEntry.getValue();

        PackageDependenciesParser parser = new PackageDependenciesParser();
        packageManagers.put(packageManagerKey.jsonKey(), parser.fromPojo(packageDependencies));
      }

      jsonObject.put(PACKAGES.jsonKey(), packageManagers);
    }

    return jsonObject;
  }