Examples of ModelMapper


Examples of org.modelmapper.ModelMapper

    }
  }

  @BeforeMethod
  protected void beforeMethod() {
    modelMapper = new ModelMapper();
    modelMapper.getConfiguration()
        .setFieldMatchingEnabled(true)
        .setSourceNameTokenizer(NameTokenizers.UNDERSCORE)
        .addValueReader(valueReader);
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

  public static void main(String... args) {
    OrderInfo orderInfo = new OrderInfo();
    orderInfo.setCustomerName("Joe Smith");
    orderInfo.setStreetAddress("1234 Main Street");

    ModelMapper modelMapper = new ModelMapper();
    Order order = modelMapper.map(orderInfo, Order.class);

    assertEquals(order.getCustomer().getName(), orderInfo.getCustomerName());
    assertEquals(order.getAddress().getStreet(), orderInfo.getStreetAddress());
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

    OrderDTO orderDTO = new OrderDTO();
    orderDTO.setStreet("1234 Pike Street");
    orderDTO.setCity("Seattle");

    // Option 1
    ModelMapper modelMapper = new ModelMapper();
    PropertyMap<OrderDTO, Order> orderMap = new PropertyMap<OrderDTO, Order>() {
      protected void configure() {
        map().getAddress().setStreet(source.getStreet());
        map().address.setCity(source.city);
      }
    };

    modelMapper.addMappings(orderMap);
    Order order = modelMapper.map(orderDTO, Order.class);

    assertEquals(order.getAddress().getStreet(), orderDTO.getStreet());
    assertEquals(order.getAddress().getCity(), orderDTO.getCity());

    // Option 2
    modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.LOOSE);
    order = modelMapper.map(orderDTO, Order.class);

    assertEquals(order.getAddress().getStreet(), orderDTO.getStreet());
    assertEquals(order.getAddress().getCity(), orderDTO.getCity());
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

    };

    ObjectGraph objectGraph = ObjectGraph.create(new WarehouseModule(orderDTO));

    Provider<?> provider = DaggerIntegration.fromDagger(objectGraph);
    ModelMapper mapper = new ModelMapper();
    mapper.getConfiguration().setProvider(provider);

    assertEquals(mapper.map(new Order(), OrderDTO.class), orderDTO);
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

  /**
   * This example demonstrates how ModelMapper automatically maps properties from Order to OrderDTO.
   */
  static void mapAutomatically() {
    Order order = createOrder();
    ModelMapper modelMapper = new ModelMapper();
    OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
    assertOrdersEqual(order, orderDTO);
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

   * This example demonstrates how ModelMapper can be used to explicitly map properties from an
   * Order to OrderDTO.
   */
  static void mapExplicitly() {
    Order order = createOrder();
    ModelMapper modelMapper = new ModelMapper();
    modelMapper.addMappings(new PropertyMap<Order, OrderDTO>() {
      @Override
      protected void configure() {
        map().setBillingStreet(source.getBillingAddress().getStreet());
        map(source.billingAddress.getCity(), destination.billingCity);
      }
    });

    OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
    assertOrdersEqual(order, orderDTO);
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

    @SuppressWarnings("deprecation")
    RootBeanDefinition bean = new RootBeanDefinition(Dest.class, false);
    beanFactory.registerBeanDefinition("bean", bean);

    Provider<?> provider = SpringIntegration.fromSpring(beanFactory);
    ModelMapper mapper = new ModelMapper();
    mapper.getConfiguration().setProvider(provider);

    assertTrue(mapper.map(new Source(), Dest.class) instanceof Dest);
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

    }
  }

  @BeforeMethod
  protected void beforeMethod() {
    modelMapper = new ModelMapper();
    modelMapper.getConfiguration()
        .setFieldMatchingEnabled(true)
        .setSourceNameTokenizer(NameTokenizers.UNDERSCORE)
        .addValueReader(new RecordValueReader());
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

      this.c = c;
    }
  }

  public void shouldSupportMultipleSourceMappings() {
    ModelMapper mapper = new ModelMapper();
    mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.LOOSE);
    mapper.getConfiguration().setAmbiguityIgnored(true);

    mapper.addMappings(new PropertyMap<FromOuter, ToOuter>() {
      protected void configure() {
        map(source.getInner().getOne()).getInner().setA(null);
        map(source.getInner().getTwo()).getInner().setB(null);
        map(source.getInner().getThree()).getInner().setC(null);
      }
    });

    FromOuter from = new FromOuter(1, 2, 3);
    ToOuter to = mapper.map(from, ToOuter.class);

    assertEquals(to.inner.a, "1");
    assertEquals(to.inner.b, "2");
    assertEquals(to.inner.c, "3");
  }
View Full Code Here

Examples of org.modelmapper.ModelMapper

      map(source.getBd()).setBd2(null);
    }
  };

  public void test() {
    ModelMapper modelMapper;
    modelMapper = new ModelMapper();
    modelMapper.addMappings(map);

    Source src = new Source();
    src.setBI(BigInteger.valueOf(4));
    src.setBd(new BigDecimal("123.123"));

    Dest dest = modelMapper.map(src, Dest.class);
    assertEquals(dest.getBI2(), src.getBI());
    assertEquals(dest.getBd2(), src.getBd());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.