Class JsonUtil
java.lang.Object
io.grpc.internal.JsonUtil
Helper utility to work with JSON values in Java types. Includes the JSON dialect used by
Protocol Buffers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longprivate static final longprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncheckObjectList(List<?> rawList) Casts a list of unchecked JSON values to a list of checked objects in Java type.checkStringList(List<?> rawList) Casts a list of unchecked JSON values to a list of String.private static booleandurationIsValid(long seconds, int nanos) Returns true if the given number of seconds and nanos is a validDuration.static BooleangetBoolean(Map<String, ?> obj, String key) Gets a boolean from an object for the given key.static List<?> Gets a list from an object for the given key.getListOfObjects(Map<String, ?> obj, String key) Gets a list from an object for the given key, and verifies all entries are objects.getListOfStrings(Map<String, ?> obj, String key) Gets a list from an object for the given key, and verifies all entries are strings.static DoublegetNumberAsDouble(Map<String, ?> obj, String key) Gets a number from an object for the given key.static FloatgetNumberAsFloat(Map<String, ?> obj, String key) Gets a number from an object for the given key.static IntegergetNumberAsInteger(Map<String, ?> obj, String key) Gets a number from an object for the given key, casted to an integer.static LonggetNumberAsLong(Map<String, ?> obj, String key) Gets a number from an object for the given key, casted to an long.Gets an object from an object for the given key.static StringGets a string from an object for the given key.static LonggetStringAsDuration(Map<String, ?> obj, String key) Gets a string from an object for the given key, parsed as a duration (defined by protobuf).private static longnormalizedDuration(long seconds, int nanos) Copy ofDurations.normalizedDuration(long, int).private static longparseDuration(String value) Parse from a string to produce a duration.private static intparseNanos(String value) Copy ofTimestamps.parseNanos(String).private static longsaturatedAdd(long a, long b) Returns the sum ofaandbunless it would overflow or underflow in which caseLong.MAX_VALUEorLong.MIN_VALUEis returned, respectively.
-
Field Details
-
DURATION_SECONDS_MIN
private static final long DURATION_SECONDS_MIN- See Also:
-
DURATION_SECONDS_MAX
private static final long DURATION_SECONDS_MAX- See Also:
-
NANOS_PER_SECOND
private static final long NANOS_PER_SECOND
-
-
Constructor Details
-
JsonUtil
public JsonUtil()
-
-
Method Details
-
getList
-
getListOfObjects
-
getListOfStrings
-
getObject
-
getNumberAsDouble
-
getNumberAsFloat
-
getNumberAsInteger
-
getNumberAsLong
-
getString
-
getStringAsDuration
-
getBoolean
-
checkObjectList
-
checkStringList
-
parseDuration
Parse from a string to produce a duration. Copy ofDurations.parse(String).- Returns:
- A Duration parsed from the string.
- Throws:
ParseException- if parsing fails.
-
parseNanos
Copy ofTimestamps.parseNanos(String).- Throws:
ParseException
-
normalizedDuration
private static long normalizedDuration(long seconds, int nanos) Copy ofDurations.normalizedDuration(long, int). -
durationIsValid
private static boolean durationIsValid(long seconds, int nanos) Returns true if the given number of seconds and nanos is a validDuration. Thesecondsvalue must be in the range [-315,576,000,000, +315,576,000,000]. Thenanosvalue must be in the range [-999,999,999, +999,999,999].Note: Durations less than one second are represented with a 0
secondsfield and a positive or negativenanosfield. For durations of one second or more, a non-zero value for thenanosfield must be of the same sign as thesecondsfield.Copy of
.invalid reference
com.google.protobuf.util.Duration#isValid -
saturatedAdd
private static long saturatedAdd(long a, long b) Returns the sum ofaandbunless it would overflow or underflow in which caseLong.MAX_VALUEorLong.MIN_VALUEis returned, respectively.Copy of
LongMath.saturatedAdd(long, long).
-