@Nullable @Override public IOException visitMarshaledReplacementNode( MarshaledReplacementObjectNode node, @Nullable DelegatingMarshalContext context) { assert context != null; return node.getChild().accept(context.nodeVisitor, NoKey.instance()); }
/** * Creates a new marshal context that delegates elementary marshal operations to the given marshal * target. * * <p>In most cases, {@link #marshal(Object, Collection, MarshalTarget)} is the more appropriate * high-level alternative to instantiating a marshal context explicitly. * * @param currentMarshaler {@link Marshaler} instance that will receive the returned marshal * context as argument to {@link Marshaler#put(Object, MarshalContext)} * @param marshalers collection of {@link Marshaler} instances to choose from when a marshaler * invokes {@link MarshalContext#writeObject(Object, Key)} recursively * @param marshalTarget marshal target used for elementary marshal operations * @return the new marshal context */ 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 void requireValidNewToken(Key key) throws MarshalingException { Objects.requireNonNull(key); if (closed) { throw new MarshalingException("Marshal context used after it was closed."); } else if (entries.contains(key)) { throw new MarshalingException(String.format("Entry with key '%s' already exists.", key)); } else if ((!(key instanceof NoKey) && entries.contains(NoKey.instance()))) { throw new MarshalingException( String.format( "Tried to add key '%s' to serialization node that already contains empty key.", key)); } else if (key instanceof NoKey && !entries.isEmpty()) { throw new MarshalingException( String.format( "Tried to add empty key to non-empty serialization node (already contains at least key '%s').", entries.iterator().next())); } }