Class JSONUtils
java.lang.Object
org.deltava.util.JSONUtils
A utility class for dealing with JSON objects.
- Since:
- 7.3
- Version:
- 11.0
- Author:
- Luke
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
ensureArrayPresent
(org.json.JSONObject o, Object... names) Ensures a JSON object has certain array properties populated.static org.json.JSONObject
format
(GeoLocation loc) Converts a location into a Google Maps LatLngLiteral JSON object.static org.json.JSONObject
Formats an Airline into a JSON object.static org.json.JSONObject
Formats an Airport into a JSON object.static org.json.JSONObject
format
(ScheduleEntry se) Formats a ScheduleEntry into a JSON object.static org.json.JSONObject
format
(FlightStatsEntry fse) Converts a FlightStatsEntry to JSON.static org.json.JSONObject
formatDate
(Instant dt) Converts an Instant into a JSON object with day/month/year components.static org.json.JSONObject
formatTime
(ZonedDateTime zdt, String fmtPattern) Converts a ZonedDateTime to a JSON object with hour, minute, second and millisecond components.
-
Method Details
-
ensureArrayPresent
Ensures a JSON object has certain array properties populated.JSONObject.accumulate(java.lang.String, java.lang.Object)
will not create an Array if only a single call is made, therefore this method will translate a JSON property that is not an Array into a single-value JSONArray.- Parameters:
o
- the JSONObjectnames
- the property names
-
format
Converts a location into a Google Maps LatLngLiteral JSON object.- Parameters:
loc
- a GeoLocation- Returns:
- a JSONObject
-
format
Formats an Airport into a JSON object.- Parameters:
a
- an Airport- Returns:
- a JSONObject
-
format
Formats an Airline into a JSON object.- Parameters:
al
- an Airline- Returns:
- a JSONObject
-
format
Formats a ScheduleEntry into a JSON object.- Parameters:
se
- a ScheduleEntry- Returns:
- a JSONObject
-
formatDate
Converts an Instant into a JSON object with day/month/year components.- Parameters:
dt
- an Instant- Returns:
- a JSONobject
-
formatTime
Converts a ZonedDateTime to a JSON object with hour, minute, second and millisecond components.- Parameters:
zdt
- a ZonedDateTimefmtPattern
- an optional formatter for the text property- Returns:
- a JSONObject
-
format
Converts a FlightStatsEntry to JSON.- Parameters:
fse
- a FlightStatsEntry- Returns:
- a JSONOebject
-