DelegatingMarshalContext implements MarshalContext { public static DelegatingMarshalContext create(Marshaler<?> currentMarshaler, Collection<? extends Marshaler<?>> marshalers, MarshalTarget marshalTarget) { Objects.requireNonNull(currentMarshaler); Objects.requireNonNull(marshalers); Objects.requireNonNull(marshalTarget); return new DelegatingMarshalContext(NoKey.instance(), marshalTarget, currentMarshaler, ImmutableList.copyOf(marshalers), null); } private  DelegatingMarshalContext(Key contextKey, MarshalTarget marshalTarget, Marshaler<?> marshaler,
            ImmutableList<Marshaler<?>> marshalers, @Nullable DelegatingMarshalContext ancestor); static DelegatingMarshalContext create(Marshaler<?> currentMarshaler,
            Collection<? extends Marshaler<?>> marshalers, MarshalTarget marshalTarget); static void marshal(Object object, Collection<? extends Marshaler<?>> marshalers,
            MarshalTarget marshalTarget); static void processMarshalingTree(ObjectNode tree, Collection<? extends Marshaler<?>> marshalers,
            MarshalTarget marshalTarget); static Marshaler<?> findMarshaler(Object object, Collection<? extends Marshaler<?>> marshalers); @Override void close(); @Override String toString(); @Override OutputStream newOutputStream(Key key); @Override void putByteSequence(ByteSequence byteSequence, Key key); @Override void writeObject(Object object, Key key); void acceptObject(Object object); void acceptTree(ObjectNode tree);  }
@Test public void create() throws IOException { MarshalingTreeBuilder treeBuilder = MarshalingTreeBuilder.create( (path, marshaler, object) -> !path.equals(Collections.singletonList(NoKey.instance())) ); TreeBuilderMarshalTarget<MarshalingTreeNode> marshalTarget = TreeBuilderMarshalTarget.create(treeBuilder); List<Marshaler<?>> marshalers = Arrays.asList(STRING_MARSHALER, INTEGER_MARSHALER); try (MarshalContext marshalContext = DelegatingMarshalContext.create(INTEGER_MARSHALER, marshalers, marshalTarget)) { INTEGER_MARSHALER.put(42, marshalContext); } Assert.assertEquals( marshalTarget.getTree(), MarshalingTreeNode.MarshaledReplacementObjectNode.of( INTEGER_MARSHALER, MarshalingTreeNode.RawObjectNode.of(STRING_MARSHALER, "42") ) ); }