Interface JSONHelper

All Known Implementing Classes:
ClassBase, EntityBase, GHActionsCache, GHAdvisory, GHAlert, GHArtifact, GHBase, GHBranch, GHEvent, GHFile, GHFileBuilder, GHGitignoreTemplate, GHHook, GHHookBuilder, GHIssue, GHIssueBuilder, GHLabel, GHLicense, GHMilestone, GHOrganisation, GHPackage, GHPages, GHPermission, GHPlan, GHProject, GHProjectBuilder, GHPublicKey, GHPublicKeyBuilder, GHPullRequest, GHRepository, GHRepositoryCache, GHSecret, GHStep, GHTeam, GHTeamBuilder, GHUser, GHVariable, GHVulnerability, GHWorkflowJob, GHWorkflowRun, Github, HttpsCertificate, SelfUser

public interface JSONHelper
This interface provides helper methods for working with JSON objects.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    This functional interface defines a method to create an object of type T from a JSON object.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> List<T>
    getArrayOrNull(org.json.JSONObject jsonObject, String key, JSONHelper.JSONToObject<T> factory)
    Returns a list of objects of type T, created from a JSON array in the JSON object using the provided factory method.
    default boolean
    getBooleanOrNull(org.json.JSONObject jsonObject, String key)
    Returns the boolean value of the specified key in the JSON object, or false if the key is not present.
    default Integer
    getIntOrNull(org.json.JSONObject jsonObject, String key)
    Returns the integer value of the specified key in the JSON object, or 0 if the key is not present.
    default List<String>
    getJSONArrayToStringList(org.json.JSONObject jsonObject, String key)
    Returns a list of strings from a JSON array in the JSON object.
    default org.json.JSONObject
    getJSONObjectOrNull(org.json.JSONObject jsonObject, String key)
    Returns the JSON object value of the specified key in the JSON object, or null if the key is not present.
    getLocalDateOrNull(org.json.JSONObject jsonObject, String key)
    Returns the OffsetDateTime value of the specified key in the JSON object, or null if the key is not present.
    default Long
    getLongOrNull(org.json.JSONObject jsonObject, String key)
    Returns the long value of the specified key in the JSON object, or 0 if the key is not present.
    default String
    getStringOrNull(org.json.JSONObject jsonObject, String key)
    Returns the string value of the specified key in the JSON object, or null if the key is not present.
  • Method Details

    • getStringOrNull

      default String getStringOrNull(org.json.JSONObject jsonObject, String key)
      Returns the string value of the specified key in the JSON object, or null if the key is not present.
      Parameters:
      jsonObject - the JSON object
      key - the key
      Returns:
      the string value or null
    • getIntOrNull

      default Integer getIntOrNull(org.json.JSONObject jsonObject, String key)
      Returns the integer value of the specified key in the JSON object, or 0 if the key is not present.
      Parameters:
      jsonObject - the JSON object
      key - the key
      Returns:
      the integer value or 0
    • getLongOrNull

      default Long getLongOrNull(org.json.JSONObject jsonObject, String key)
      Returns the long value of the specified key in the JSON object, or 0 if the key is not present.
      Parameters:
      jsonObject - the JSON object
      key - the key
      Returns:
      the long value or 0
    • getBooleanOrNull

      default boolean getBooleanOrNull(org.json.JSONObject jsonObject, String key)
      Returns the boolean value of the specified key in the JSON object, or false if the key is not present.
      Parameters:
      jsonObject - the JSON object
      key - the key
      Returns:
      the boolean value or false
    • getJSONObjectOrNull

      default org.json.JSONObject getJSONObjectOrNull(org.json.JSONObject jsonObject, String key)
      Returns the JSON object value of the specified key in the JSON object, or null if the key is not present.
      Parameters:
      jsonObject - the JSON object
      key - the key
      Returns:
      the JSON object value or null
    • getLocalDateOrNull

      default OffsetDateTime getLocalDateOrNull(org.json.JSONObject jsonObject, String key)
      Returns the OffsetDateTime value of the specified key in the JSON object, or null if the key is not present.
      Parameters:
      jsonObject - the JSON object
      key - the key
      Returns:
      the OffsetDateTime value or null
    • getArrayOrNull

      default <T> List<T> getArrayOrNull(org.json.JSONObject jsonObject, String key, JSONHelper.JSONToObject<T> factory)
      Returns a list of objects of type T, created from a JSON array in the JSON object using the provided factory method. If the key is not present, returns null.
      Parameters:
      jsonObject - the JSON object
      key - the key
      factory - the factory method to create objects of type T from a JSON object
      Returns:
      the list of objects or null
    • getJSONArrayToStringList

      default List<String> getJSONArrayToStringList(org.json.JSONObject jsonObject, String key)
      Returns a list of strings from a JSON array in the JSON object. If the key is not present or the array is empty, returns an empty list.
      Parameters:
      jsonObject - the JSON object
      key - the key
      Returns:
      the list of strings