/** * Map a field value to a string, either directly or via the symbolic map. * * @param field the object field to examine * * @return the resulting string, or null if invalid */ @Nullable protected String desymbolize(@Nonnull final JsonValue field) { switch (field.getValueType()) { case STRING: return ((JsonString) field).getString(); case NUMBER: return symbolics.inverse().get(((JsonNumber) field).intValueExact()); default: return null; } }
/** * Map a field value to a string, either directly or via the symbolic map. * * @param field the object field to examine * * @return the resulting string, or null if invalid */ @Nullable protected String desymbolize(@Nonnull final JsonValue field) { if (field == null) { return null; } switch (field.getValueType()) { case STRING: return ((JsonString) field).getString(); case NUMBER: return symbolics.inverse().get(((JsonNumber) field).intValueExact()); default: return null; } }
/** * Map a field value to a string, either directly or via the symbolic map. * * @param field the object field to examine * * @return the resulting string, or null if invalid */ @Nullable protected String desymbolize(@Nonnull final JsonValue field) { if (field == null) { return null; } switch (field.getValueType()) { case STRING: return ((JsonString) field).getString(); case NUMBER: return symbolics.inverse().get(((JsonNumber) field).intValueExact()); default: return null; } }
@Override public Integer deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return ( (JsonNumber) json ).intValueExact(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0 : Integer.parseInt( string ); default: throw new SerializationException( "Don't know how to deserialize Integer from " + json ); } } }
@Override public Integer deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return ( (JsonNumber) json ).intValueExact(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0 : Integer.parseInt( string ); default: throw new SerializationException( "Don't know how to deserialize Integer from " + json ); } } }
@Override public Short deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return (short) ( (JsonNumber) json ).intValueExact(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0 : Short.parseShort( string ); default: throw new SerializationException( "Don't know how to deserialize Short from " + json ); } } }
@Override public Byte deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return (byte) ( (JsonNumber) json ).intValueExact(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0 : Byte.parseByte( string ); default: throw new SerializationException( "Don't know how to deserialize Byte from " + json ); } } }
@Override public Short deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return (short) ( (JsonNumber) json ).intValueExact(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0 : Short.parseShort( string ); default: throw new SerializationException( "Don't know how to deserialize Short from " + json ); } } }
@Override public Byte deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize ) { switch( json.getValueType() ) { case NULL: return null; case NUMBER: return (byte) ( (JsonNumber) json ).intValueExact(); case STRING: String string = ( (JsonString) json ).getString(); return string.isEmpty() ? 0 : Byte.parseByte( string ); default: throw new SerializationException( "Don't know how to deserialize Byte from " + json ); } } }
/** * Un-marshals an integer, or returns the default value if it's not able to. * * @param jObject the JSON object * @param name the attribute name where the integer is stored * @param defaultValue the value to use if no attribute is found * @return the message integer * @throws MessageDecodeException if the field is of the wrong type */ static int intOptional(JsonObject jObject, String name, int defaultValue) throws MessageDecodeException { try { JsonNumber jsonNumber = jObject.getJsonNumber(name); if (jsonNumber == null) { return defaultValue; } else { return jsonNumber.intValueExact(); } } catch (ClassCastException | ArithmeticException e) { throw MessageDecodeException.wrongAttributeType(jObject, name, "integer"); } }
/** * Un-marshals an integer, or throws an exception if it's not able to. * * @param jObject the JSON object * @param name the attribute name where the integer is stored * @return the message integer * @throws MessageDecodeException if the field is missing or of the wrong type */ static int intMandatory(JsonObject jObject, String name) throws MessageDecodeException { try { JsonNumber jsonNumber = jObject.getJsonNumber(name); if (jsonNumber == null) { throw MessageDecodeException.missingMandatoryAttribute(jObject, name); } else { return jsonNumber.intValueExact(); } } catch (ClassCastException | ArithmeticException e) { throw MessageDecodeException.wrongAttributeType(jObject, name, "integer"); } }
int intValue = number.intValueExact(); if (type == Integer.class || type == int.class) { return intValue;
int intValue = number.intValueExact(); if (type == Integer.class || type == int.class) { return intValue;
return l; return number.intValueExact(); } catch (ArithmeticException ex) { return number.bigIntegerValueExact();
final JsonValue value = object.get(EMPTY_VALUE_FIELD); if (value instanceof JsonNumber) { if (((JsonNumber) value).intValueExact() == 0) { return EmptyAttributeValue.NULL; } else {