SlimeUtils { public static Slime jsonToSlimeOrThrow(String json) { return jsonToSlimeOrThrow(json.getBytes(StandardCharsets.UTF_8)); }  static void copyObject(Inspector from, Cursor to); static byte[] toJsonBytes(Slime slime); static byte[] toJsonBytes(Inspector inspector); static Slime jsonToSlime(byte[] json); static Slime jsonToSlime(String json); static Slime jsonToSlimeOrThrow(String json); static Slime jsonToSlimeOrThrow(byte[] json); static Optional<String> optionalString(Inspector inspector); static Optional<Long> optionalLong(Inspector inspector); static Iterator<Inspector> entriesIterator(Inspector inspector); static Stream<Inspector> entriesStream(Inspector inspector);  }
@Test public void test_json_to_slime_or_throw() { Slime slime = SlimeUtils.jsonToSlimeOrThrow("{\"foo\":\"foobie\",\"bar\":{}}"); assertThat(slime.get().field("foo").asString(), is("foobie")); assertTrue(slime.get().field("bar").valid()); }
@Test public void test_invalid_json() { try { SlimeUtils.jsonToSlimeOrThrow("foo"); fail(); } catch (RuntimeException e) { assertEquals("Unexpected character 'o'", e.getMessage()); } }