Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class JsonValues
- Object
- JsonValues
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.
Methods
Inherited methods
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
jsonis 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
sis not ISO-8601
at
public static IllegalArgumentException at(String path, IllegalArgumentException e)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.getString
public static String getString(Map m, String key)Reads a scalar member of a parsed JSON object as a string.
Parameters
mMap- the JSON object, may be null
keyString- the member name
Returns
the member’s string form, or null when the object is null, the member
is absent, JSON null (or the string
"null"), an object or an arraygetMap
public static Map<String, Object> getMap(Map m, String key)Reads a member of a parsed JSON object that is itself an object.
Parameters
mMap- the JSON object, may be null
keyString- the member name
Returns
the nested object, or null when it is absent or not an object
getDouble
public static double getDouble(Map m, String key, double def)Reads a numeric member of a parsed JSON object.
Parameters
mMap- the JSON object, may be null
keyString- the member name
defdouble- the value answered when the member is absent or not a number
Returns
the member as a double, or
def