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).
 *
 */
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 {@code null} if source is {@code null}.
   */
   T map(Object source, Class targetClass);

  /**
   * A type-safe variant of {@link #map(Object, Class)} to prevent accidental abuse (e.g. mapping of apples to bananas).
   *
   * @param  is a common super-type (interface) of source and targetType.
   * @param  is the generic type of source.
   * @param  is the generic type to convert to (target).
   * @param apiClass is the {@link Class} reflecting the {@literal }.
   * @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 {@code null} if source is {@code null}.
   * @since 1.3.0
   */
   T mapTypesafe(Class apiClass, S 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}. Uses {@code false} for suppressNullValues (see
   * {@link #mapList(List, Class, boolean)}).
   *
   * @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 {@code null}.
   */
   List mapList(List 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.
   * @param suppressNullValues {@code true} if {@code null} values shall be suppressed/omitted in the
   *        resulting {@link List}, {@code false} otherwise.
   * @return the {@link List} with the converted objects. Will be {@link List#isEmpty() empty} is source is
   *         empty or {@code null}.
   * @since 1.3.0
   */
   List mapList(List source, Class targetClass, boolean suppressNullValues);

  /**
   * 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}. Uses {@code false} for suppressNullValues (see
   * {@link #mapSet(Set, Class, boolean)}).
   *
   * @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 {@code null}.
   */
   Set mapSet(Set 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.
   * @param suppressNullValues {@code true} if {@code null} values shall be suppressed/omitted in the
   *        resulting {@link Set}, {@code false} otherwise.
   * @return the {@link Set} with the converted objects. Will be {@link Set#isEmpty() empty} is source is
   *         empty or {@code null}.
   * @since 1.3.0
   */
   Set mapSet(Set source, Class targetClass, boolean suppressNullValues);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy