|
35 | 35 | import java.util.Collection;
|
36 | 36 | import java.util.Collections;
|
37 | 37 | import java.util.HashSet;
|
| 38 | +import java.util.Locale; |
38 | 39 | import java.util.Map;
|
39 | 40 | import java.util.Set;
|
40 | 41 | import java.util.WeakHashMap;
|
@@ -842,11 +843,19 @@ private final Object parseValue(Field fieldContext,
|
842 | 843 | }
|
843 | 844 | throw new IllegalArgumentException("expected numeric type but got " + valueType);
|
844 | 845 | case VALUE_STRING:
|
845 |
| - Preconditions.checkArgument(valueClass == null |
| 846 | + //TODO(user): Maybe refactor this method in multiple mini-methods for readability? |
| 847 | + String text = getText().trim().toLowerCase(Locale.US); |
| 848 | + // If we are expecting a Float / Double and the Text is NaN (case insensitive) |
| 849 | + // Then: Accept, even if the Annotation is JsonString. |
| 850 | + // Otherwise: Check that the Annotation is not JsonString. |
| 851 | + if (!(((valueClass == float.class || valueClass == Float.class) |
| 852 | + || (valueClass == double.class || valueClass == Double.class)) |
| 853 | + && (text.equals("nan") || text.equals("infinity") || text.equals("-infinity")))) { |
| 854 | +
64B2
Preconditions.checkArgument(valueClass == null |
846 | 855 | || !Number.class.isAssignableFrom(valueClass) || fieldContext != null
|
847 | 856 | && fieldContext.getAnnotation(JsonString.class) != null,
|
848 | 857 | "number field formatted as a JSON string must use the @JsonString annotation");
|
849 |
| - // TODO(yanivi): "special" values like Double.POSITIVE_INFINITY? |
| 858 | + } |
850 | 859 | return Data.parsePrimitiveValue(valueType, getText());
|
851 | 860 | case VALUE_NULL:
|
852 | 861 | Preconditions.checkArgument(valueClass == null || !valueClass.isPrimitive(),
|
|
0 commit comments