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

io.oasp.module.beanmapping.common.api.BeanMapper Maven / Gradle / Ivy

Go to download

Minimal shim for bean mapping to convert between compatible Java beans (e.g. JPA entity to transfer-object and vice versa).

There is a newer version: 3.0.0
Show newest version
package io.oasp.module.beanmapping.common.api;

import java.util.List;
import java.util.Set;

/**
 * This is the interface used to convert from one Java bean to another compatible bean (e.g. from a JPA entity to a
 * corresponding transfer-object).
 * 
 * @author hohwille
 */
public interface BeanMapper {

  /**
   * Recursively converts the given source {@link Object} to the given target {@link Class}.
   * 
   * @param  is the generic type to convert to.
   * @param source is the object to convert.
   * @param targetClass is the {@link Class} reflecting the type to convert to.
   * @return the converted object. Will be null if source is null.
   */
   T map(Object source, Class targetClass);

  /**
   * Creates a new {@link List} with the {@link #map(Object, Class) mapped bean} for each {@link List#get(int) entry} of
   * the given {@link List}.
   * 
   * @param  is the generic type to convert the {@link List} entries to.
   * @param source is the {@link List} with the source objects.
   * @param targetClass is the {@link Class} reflecting the type to convert each {@link List} entry to.
   * @return the {@link List} with the converted objects. Will be {@link List#isEmpty() empty} is source is
   *         empty or null.
   */
   List mapList(List source, Class targetClass);

  /**
   * Creates a new {@link Set} with the {@link #map(Object, Class) mapped bean} for each {@link Set#contains(Object)
   * entry} of the given {@link Set}.
   * 
   * @param  is the generic type to convert the {@link Set} entries to.
   * @param source is the {@link Set} with the source objects.
   * @param targetClass is the {@link Class} reflecting the type to convert each {@link Set} entry to.
   * @return the {@link Set} with the converted objects. Will be {@link Set#isEmpty() empty} is source is
   *         empty or null.
   */
   Set mapSet(Set source, Class targetClass);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy