All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mServer.crawler.sender.orf.JsonUtils Maven / Gradle / Ivy

There is a newer version: 3.1.64
Show newest version
package mServer.crawler.sender.orf;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.Optional;

public final class JsonUtils {

  private JsonUtils() {
    super();
  }

  /**
   * Gets the value of an attribute
   *
   * @param aJsonObject the object
   * @param aAttributeName the name of the attribute
   * @return the value of the attribute, if it exists, else Optional.empty
   */
  public static Optional getAttributeAsString(final JsonObject aJsonObject,
          final String aAttributeName) {
    if (aJsonObject.has(aAttributeName)) {
      final JsonElement aElement = aJsonObject.get(aAttributeName);
      if (!aElement.isJsonNull()) {
        return Optional.of(aElement.getAsString());
      }
    }

    return Optional.empty();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy