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

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

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

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

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.function.Function;

/**
 * Generic marshaller based on a single non-public field.
 * @param  the marshaller target type
 * @param  the field type
 * @author Paul Ferraro
 */
public class UnaryFieldMarshaller extends UnaryMemberMarshaller {

	public UnaryFieldMarshaller(Class targetClass, Class fieldClass, Function factory) {
		super(targetClass, Reflect::getValue, Reflect::findField, fieldClass, factory);
	}

	public UnaryFieldMarshaller(Class targetClass, Class fieldClass) {
		this(targetClass, fieldClass, Reflect.getConstructor(targetClass, fieldClass));
	}

	private UnaryFieldMarshaller(Class targetClass, Class fieldClass, Constructor constructor) {
		this(targetClass, fieldClass, new Function<>() {
			@Override
			public T apply(F value) {
				return Reflect.newInstance(constructor, value);
			}
		});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy