Class JsonValues

java.lang.Object
com.codename1.mapping.JsonValues

public final class JsonValues extends Object

Conversions the generated @Mapped mappers share: the lenient readers for @JsonFormat fields, ISO-8601 dates computed by arithmetic, and the path prefixing of a nested failure. Called only from generated code.

Nothing here consults a locale or a time zone: neither is guaranteed on a device, and a wire format must not depend on the phone's settings. Dates are always written in UTC.

  • Method Summary

    Modifier and Type
    Method
    Description
    Prefixes a nested failure with the location it happened at.
    static String
    Formats d as yyyy-MM-ddTHH:mm:ss.SSSZ in UTC.
    static Object
    object(Mapper mapper, Object json)
    json read by mapper, which must be a JSON object.
    static long
    Parses an ISO-8601 date or date-time to epoch milliseconds.
    static Date
    A JSON date in either shape: epoch milliseconds (a number or a numeric string) or an ISO-8601 string -- a date alone, or a date and time with optional fraction and Z or numeric offset.
    static double
    A JSON number, or a string holding one, as a double.
    static long
    toIntegral(Object v, long min, long max)
    A JSON whole number in [min, max], for an array element of an integral type: a fraction or a value out of range is refused rather than truncated, as the server's codec refuses it.
    static long
    A JSON number, or a string holding one, as a long.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toLong

      public static long toLong(Object v)

      A JSON number, or a string holding one, as a long.

      Throws
      • IllegalArgumentException: when the value is neither
    • toIntegral

      public static long toIntegral(Object v, long min, long max)

      A JSON whole number in [min, max], for an array element of an integral type: a fraction or a value out of range is refused rather than truncated, as the server's codec refuses it.

      Throws
      • IllegalArgumentException: when the value is not such a number
    • object

      public static Object object(Mapper mapper, Object json)

      json read by mapper, which must be a JSON object.

      Throws
      • IllegalArgumentException: when json is not an object
    • toDouble

      public static double toDouble(Object v)

      A JSON number, or a string holding one, as a double.

      Throws
      • IllegalArgumentException: when the value is neither
    • toDate

      public static Date toDate(Object v)

      A JSON date in either shape: epoch milliseconds (a number or a numeric string) or an ISO-8601 string -- a date alone, or a date and time with optional fraction and Z or numeric offset.

      Throws
      • IllegalArgumentException: when the value is neither
    • formatIso

      public static String formatIso(Date d)
      Formats d as yyyy-MM-ddTHH:mm:ss.SSSZ in UTC.
    • parseIso

      public static long parseIso(String s)

      Parses an ISO-8601 date or date-time to epoch milliseconds. A value with no offset is read as UTC.

      Throws
      • IllegalArgumentException: when s is not ISO-8601
    • at

      Prefixes a nested failure with the location it happened at. A message that already starts with a $ path is joined to it, so a failure three levels down reads $.order.items[2].due: required member is missing.