MarshalingTreeBuilder implements TreeBuilder<MarshalingTreeNode> { public static ObjectNode processMarshalingTree(ObjectNode tree, Collection<? extends Marshaler<?>> marshalers, ShouldMarshalPredicate shouldMarshalPredicate) throws IOException { MarshalingTreeBuilder treeBuilder = create(shouldMarshalPredicate); return (ObjectNode) TreeBuilderMarshalTarget.processMarshalingTree(tree, marshalers, treeBuilder); } private  MarshalingTreeBuilder(ShouldMarshalPredicate shouldMarshalPredicate, List<Key> path); static MarshalingTreeBuilder create(ShouldMarshalPredicate shouldMarshalPredicate); static ObjectNode marshal(Object object, Collection<? extends Marshaler<?>> marshalers,
            ShouldMarshalPredicate shouldMarshalPredicate); static ObjectNode processMarshalingTree(ObjectNode tree, Collection<? extends Marshaler<?>> marshalers,
            ShouldMarshalPredicate shouldMarshalPredicate); @Override boolean shouldMarshal(Marshaler<?> marshaler, Object object); @Override RawObjectNode createObjectNode(Marshaler<?> marshaler, Object object); @Override ByteSequenceNode createByteSequenceNode(ByteSequence byteSequence); @Override MarshaledReplacementObjectNode createRedirectNode(Marshaler<?> marshaler, MarshalingTreeNode child); @Override MarshaledObjectNode createParentNode(Marshaler<?> marshaler, Map<Key, MarshalingTreeNode> children); @Override MarshalingTreeBuilder resolve(Key key);  }
@Test public void processMarshalingTreeInteger() throws IOException { ObjectNode source = MarshaledReplacementObjectNode.of( INTEGER_MARSHALER, RawObjectNode.of(STRING_MARSHALER, "42") ); List<Marshaler<?>> marshalers = Arrays.asList(STRING_MARSHALER, INTEGER_MARSHALER); ObjectNode actual = MarshalingTreeBuilder.processMarshalingTree(source, marshalers, (path, marshaler, object) -> true); Assert.assertEquals( actual, MarshaledReplacementObjectNode.of( INTEGER_MARSHALER, MarshaledReplacementObjectNode.of( STRING_MARSHALER, ByteSequenceNode.of(ByteSequences.arrayBacked("42".getBytes(StandardCharsets.UTF_8))) ) ) ); Assert.assertEquals( MarshalingTreeBuilder.processMarshalingTree(actual, marshalers, (path, marshaler, object) -> true), MarshaledReplacementObjectNode.of( INTEGER_MARSHALER, MarshaledReplacementObjectNode.of( STRING_MARSHALER, ByteSequenceNode.of(ByteSequences.arrayBacked("42".getBytes(StandardCharsets.UTF_8))) ) ) ); }