GithubHelp home page GithubHelp logo

Comments (6)

roookeee avatar roookeee commented on May 21, 2024 1

Your call :) Maybe just make a comment in the readme that you expect or don't expect new mappers to handle null, a unit test would do too. Thanks for your time. If you change your mind give me a heads up, will do a PR then

from java-object-mapper-benchmark.

roookeee avatar roookeee commented on May 21, 2024

I would volunteer for a PR if this issue is accepted

from java-object-mapper-benchmark.

arey avatar arey commented on May 21, 2024

The 2 source and target data structures are similar. There is no upper case conversion or lastname + firstname to name conversion. Thus nullable fields should not be a problem. Nullable relationship or empty collections could be.
Before going further, I would like some precisions. Just a few samples could be fine.

from java-object-mapper-benchmark.

roookeee avatar roookeee commented on May 21, 2024

Looking at the manual implementation everything is indeed null checked but the input values for the benchmark are never null. One could conclude that 1) the manual implementation does unnecessary null checks and may lose some performance compared to the mapping frameworks or 2) that the input of the benchmark does not reflect the nullability of some fields.

What I am proposing: use Order values in the benchmark that actually have null values. As I see it most if not all mappers included in this repository do a null check implicitly (without further configuration) BUT some mappers might need additional configuration to add a null check (see my just added datus implementation). I could have omitted the null checks as I know that the current benchmark values are never null which would improve datus performance - cheating yes, but there is no unit test that shows that all mappers can handle null fields of the input value and the benchmark doesn't reflect null values in the fields too. I would propose the following unit-test and benchmark cases:

//case 1: everything is present
Order order1 = new Order();
Customer customer = new Customer();
order1.setCustomer(customer);
customer.setName("Joe Smith");
Address billingAddress = new Address();
customer.setBillingAddress(billingAddress);
billingAddress.setStreet("1234 Market Street");
billingAddress.setCity("San Fran");
Address shippingAddress = new Address();
customer.setShippingAddress(shippingAddress);
shippingAddress.setStreet("1234 West Townsend");
shippingAddress.setCity("Boston");
List<Product> products = new ArrayList<Product>(2);
order1.setProducts(products);
products.add(new Product("socks"));
products.add(new Product("shoes"));

//case 2: everything is null
Order order2 = new Order();

//case 3: some fields are null (both addresses)
Order order3 = new Order();
Customer customer3 = new Customer();
order3.setCustomer(customer3);
customer3.setName("Joe Smith");
customer3.setShippingAddress(shippingAddress);
shippingAddress.setStreet("1234 West Townsend");
shippingAddress.setCity("Boston");
List<Product> products3 = new ArrayList<Product>(2);
order3.setProducts(products3);
products3.add(new Product("socks"));
products3.add(new Product("shoes"));

from java-object-mapper-benchmark.

arey avatar arey commented on May 21, 2024

I've done a test with the partial Order (case 3).
Only the Jmapper test fails and requires some additional configuration :

com.googlecode.jmapper.exceptions.JMapperException: com.googlecode.jmapper.exceptions.NestedBeanNullException: the field street is null, error occured in mapping phase between the fields: OrderDTO.shippingStreetAddress and Order.customer

	at com.googlecode.jmapper.config.JmapperLog.error(JmapperLog.java:46)
	at com.googlecode.jmapper.JMapper.getDestination(JMapper.java:100)
	at com.javaetmoi.benchmark.mapping.mapper.jmapper.JMapperMapper.map(JMapperMapper.java:35)
	at com.javaetmoi.benchmark.mapping.mapper.dozer.AbstractMapperTest.map(AbstractMapperTest.java:16)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: com.googlecode.jmapper.exceptions.NestedBeanNullException: the field street is null, error occured in mapping phase between the fields: OrderDTO.shippingStreetAddress and Order.customer
	at com.googlecode.jmapper.config.Error.nestedBeanNull(Error.java:127)
	at comjavaetmoibenchmarkmappingmodeldtoOrderDTOcomjavaetmoibenchmarkmappingmodelentityOrder741697001.nullVSouAllAll(comjavaetmoibenchmarkmappingmodeldtoOrderDTOcomjavaetmoibenchmarkmappingmodelentityOrder741697001.java)
	at com.googlecode.jmapper.JMapper.getDestination(JMapper.java:98)
	... 32 more

I'm not sure to add those kind of test. I'll prefer to enhance the model with more advanced features: enum mapping, transcoding, String to numeric conversion ...

from java-object-mapper-benchmark.

arey avatar arey commented on May 21, 2024

Thank you. I've added some unit tests and complete the readme.md.

from java-object-mapper-benchmark.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.