Class JSONUtils

java.lang.Object
org.deltava.util.JSONUtils

public class JSONUtils extends Object
A utility class for dealing with JSON objects.
Since:
7.3
Version:
11.0
Author:
Luke
  • Method Details

    • ensureArrayPresent

      public static void ensureArrayPresent(org.json.JSONObject o, Object... names)
      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 JSONObject
      names - the property names
    • format

      public static org.json.JSONObject format(GeoLocation loc)
      Converts a location into a Google Maps LatLngLiteral JSON object.
      Parameters:
      loc - a GeoLocation
      Returns:
      a JSONObject
    • format

      public static org.json.JSONObject format(Airport a)
      Formats an Airport into a JSON object.
      Parameters:
      a - an Airport
      Returns:
      a JSONObject
    • format

      public static org.json.JSONObject format(Airline al)
      Formats an Airline into a JSON object.
      Parameters:
      al - an Airline
      Returns:
      a JSONObject
    • format

      public static org.json.JSONObject format(ScheduleEntry se)
      Formats a ScheduleEntry into a JSON object.
      Parameters:
      se - a ScheduleEntry
      Returns:
      a JSONObject
    • formatDate

      public static org.json.JSONObject formatDate(Instant dt)
      Converts an Instant into a JSON object with day/month/year components.
      Parameters:
      dt - an Instant
      Returns:
      a JSONobject
    • formatTime

      public static org.json.JSONObject formatTime(ZonedDateTime zdt, String fmtPattern)
      Converts a ZonedDateTime to a JSON object with hour, minute, second and millisecond components.
      Parameters:
      zdt - a ZonedDateTime
      fmtPattern - an optional formatter for the text property
      Returns:
      a JSONObject
    • format

      public static org.json.JSONObject format(FlightStatsEntry fse)
      Converts a FlightStatsEntry to JSON.
      Parameters:
      fse - a FlightStatsEntry
      Returns:
      a JSONOebject