All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.clustering.marshalling.protostream.reflect.ProxyMarshaller Maven / Gradle / Ivy

/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.marshalling.protostream.reflect;

import java.io.IOException;
import java.lang.reflect.Method;

import org.wildfly.clustering.marshalling.protostream.FunctionalScalarMarshaller;
import org.wildfly.clustering.marshalling.protostream.Scalar;
import org.wildfly.common.function.ExceptionFunction;

/**
 * Marshaller for proxies serialized using the writeReplace()/readResolve() pattern.
 * @author Paul Ferraro
 */
public class ProxyMarshaller extends FunctionalScalarMarshaller {

    public ProxyMarshaller(Class targetClass) {
        super(targetClass, Scalar.ANY, new ExceptionFunction() {
            @Override
            public Object apply(T object) throws IOException {
                Method method = Reflect.findMethod(object.getClass(), "writeReplace");
                return Reflect.invoke(object, method);
            }
        }, new ExceptionFunction() {
            @Override
            public T apply(Object proxy) throws IOException {
                Method method = Reflect.findMethod(proxy.getClass(), "readResolve");
                return Reflect.invoke(proxy, method, targetClass);
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy