SlimeUtils { public static void copyObject(Inspector from, Cursor to) { if (from.type() != Type.OBJECT) { throw new IllegalArgumentException("Cannot copy object: " + from); } from.traverse((ObjectTraverser) (name, inspector) -> setObjectEntry(inspector, name, to)); }  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_copying_slime_types_into_cursor() { Slime slime = new Slime(); Cursor root = slime.setObject(); root.setString("foo", "foobie"); Cursor subobj = root.setObject("bar"); Slime slime2 = new Slime(); Cursor root2 = slime2.setObject(); root2.setString("a", "a"); root2.setLong("b", 2); root2.setBool("c", true); root2.setDouble("d", 3.14); root2.setData("e", new byte[]{0x64}); root2.setNix("f"); SlimeUtils.copyObject(slime2.get(), subobj); assertThat(root.toString(), is("{\"foo\":\"foobie\",\"bar\":{\"a\":\"a\",\"b\":2,\"c\":true,\"d\":3.14,\"e\":\"0x64\",\"f\":null}}")); }
@Test public void test_copying_slime_arrays_into_cursor() { Slime slime = new Slime(); Cursor root = slime.setObject(); root.setString("foo", "foobie"); Cursor subobj = root.setObject("bar"); Slime slime2 = new Slime(); Cursor root2 = slime2.setObject(); Cursor array = root2.setArray("a"); array.addString("foo"); array.addLong(4); array.addBool(true); array.addDouble(3.14); array.addNix(); array.addData(new byte[]{0x64}); Cursor objinner = array.addObject(); objinner.setString("inner", "binner"); SlimeUtils.copyObject(slime2.get(), subobj); assertThat(root.toString(), is("{\"foo\":\"foobie\",\"bar\":{\"a\":[\"foo\",4,true,3.14,null,\"0x64\",{\"inner\":\"binner\"}]}}")); }