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 ClassesModifier and TypeInterfaceDescriptionstatic interface
This functional interface defines a method to create an object of type T from a JSON object. -
Method Summary
Modifier and TypeMethodDescriptiondefault <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.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.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.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
Returns the string value of the specified key in the JSON object, or null if the key is not present.- Parameters:
jsonObject
- the JSON objectkey
- the key- Returns:
- the string value or null
-
getIntOrNull
Returns the integer value of the specified key in the JSON object, or 0 if the key is not present.- Parameters:
jsonObject
- the JSON objectkey
- the key- Returns:
- the integer value or 0
-
getLongOrNull
Returns the long value of the specified key in the JSON object, or 0 if the key is not present.- Parameters:
jsonObject
- the JSON objectkey
- the key- Returns:
- the long value or 0
-
getBooleanOrNull
Returns the boolean value of the specified key in the JSON object, or false if the key is not present.- Parameters:
jsonObject
- the JSON objectkey
- the key- Returns:
- the boolean value or false
-
getJSONObjectOrNull
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 objectkey
- the key- Returns:
- the JSON object value or null
-
getLocalDateOrNull
Returns the OffsetDateTime value of the specified key in the JSON object, or null if the key is not present.- Parameters:
jsonObject
- the JSON objectkey
- 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 objectkey
- the keyfactory
- the factory method to create objects of type T from a JSON object- Returns:
- the list of objects or null
-
getJSONArrayToStringList
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 objectkey
- the key- Returns:
- the list of strings
-