Convert { public static Multimap<String, Object> jsonToJava(String json) { try (JsonReader reader = new JsonReader(new StringReader(json))) { reader.setLenient(true); return jsonToJava(reader); } catch (IOException e) { throw CheckedExceptions.wrapAsRuntimeException(e); } } private  Convert(); static List<Multimap<String, Object>> anyJsonToJava(String json); static TObject javaToThrift(Object object); static Multimap<String, Object> jsonToJava(String json); @SuppressWarnings("unchecked") static String mapsToJson(Collection<Multimap<String, Object>> list); static String mapToJson(Map<String, ?> map); static String mapToJson(Multimap<String, Object> map); static String operatorToString(Operator operator); @SuppressWarnings("unchecked") static T possibleThriftToJava(Object tobject); static Object stringToJava(String value); static Operator stringToOperator(String symbol); static String stringToResolvableLinkInstruction(String ccl); @Deprecated static String stringToResolvableLinkSpecification(String key,
            String rawValue); static Object thriftToJava(TObject object); static Object toFunctionOrUnescapedValueIfPossible(Object value);  }
@Test(expected = JsonParseException.class) public void testCannConvertJsonArrayWithNonPrimitives() { Convert.jsonToJava("{\"key\": [1, [2, 3]]}"); }
@Test(expected = JsonParseException.class) public void testCannontConvertInvalidJsonString() { Convert.jsonToJava(Random.getString()); }
@Test(expected = JsonParseException.class) public void testCannotConvertJsonLeadingWithArray() { Convert.jsonToJava("[\"a\",\"b\",\"c\"]"); }
@Test(expected = JsonParseException.class) public void testCannotConvertJsonStringWithEmbeddedObject() { Convert.jsonToJava("{\"key\": {\"a\": 1}}"); }
@Test public void testConvertJsonArray() { int intValue = Random.getInt(); String string = Random.getString(); boolean bool = Random.getBoolean(); long longVal = Random.getLong(); float floatVal = Random.getFloat(); double doubleVal = Random.getDouble(); Set<Object> expected = Sets.<Object> newHashSet(intValue, string, bool, longVal, floatVal, doubleVal); String json = "{\"array\": [" + intValue + ", \"" + string + "\", " + bool + ", " + longVal + ", " + floatVal + ", \"" + doubleVal + "D\"]}"; Multimap<String, Object> data = Convert.jsonToJava(json); Set<Object> values = Sets.newHashSet(data.get("array")); Set<Object> oddMenOut = Sets.symmetricDifference(expected, values); Assert.assertEquals(0, oddMenOut.size()); }
@Test public void testConvertJsonArrayDupesAreFilteredOut() { String json = "{\"key\": [3, 3]}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals(1, data.size()); }
@Test public void testConvertJsonBoolean() { boolean value = Random.getBoolean(); String json = "{\"elt\": " + value + "}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals(value, Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonDouble() { double value = Random.getDouble(); String json = "{\"elt\": \"" + value + "D\"}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals(value, Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonFloat() { float value = Random.getFloat(); String json = "{\"elt\": " + value + "}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals(value, Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonInteger() { int value = Random.getInt(); String json = "{\"elt\": " + value + "}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals(value, Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonLong() { long value = Random.getLong(); String json = "{\"elt\": " + value + "}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals(value, Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonString() { String value = Random.getString(); String json = "{\"elt\": \"" + value + "\"}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals(value, Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonStringBoolean() { boolean value = Random.getBoolean(); String json = "{\"elt\": \"" + value + "\"}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals("" + value + "", Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonStringNumber() { Number value = Random.getNumber(); String json = "{\"elt\": \"" + value + "\"}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals("" + value + "", Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonStringNumberReproA() { Number value = 0.5907014118838035; String json = "{\"elt\": \"" + value + "\"}"; Multimap<String, Object> data = Convert.jsonToJava(json); Assert.assertEquals("" + value + "", Iterables.getOnlyElement(data.get("elt"))); }
@Test public void testConvertJsonWithMasqueradingDouble() { String json = "{\"double\": \"3.14D\"}"; Multimap<String, Object> converted = Convert.jsonToJava(json); Assert.assertEquals(3.14, converted.get("double").iterator().next()); }