Giter Site home page Giter Site logo

Comments (4)

zafar-iqbal avatar zafar-iqbal commented on July 19, 2024

Please anyone know it, When this issue will be fixed?
single property to property of collection element.

from orika.

brabenetz avatar brabenetz commented on July 19, 2024

The 'NullpointerException' is fixed by #175.
But the Example Code will only work for mapping to an existing instance which already have one or more elements (works after Bugfix #175 ):

MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(A.class, B.class)
	.field("stringA", "elementsSet{stringB}")
	.register();

A a = new A();
a.setStringA("test");

// Instead of: B b = mapperFactory.getMapperFacade().map(a, B.class);
B b = new B();
b.getElementsSet().add(new BSetElement());
mapperFactory.getMapperFacade().map(a, b);

assertThat(b.getElementsSet(), hasSize(1));
assertThat(b.getElementsSet().iterator().next().getStringB(), is("test"));

A Workaround could be to use the indexed-Expression, but this is only Supported if the Collection is a java.util.List:

MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(A.class, B.class)
	.field("stringA", "elementsList[0].stringB")
	.register();

A a = new A();
a.setStringA("test");

B b = mapperFactory.getMapperFacade().map(a, B.class);

assertThat(b.getElementsList(), hasSize(1));
assertThat(b.getElementsList().iterator().next().getStringB(), is("test"));

Another Workaround can be a CustomMapper

MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(A.class, B.class)
	.customize(new CustomMapper<A, B>() {
		@Override
		public void mapAtoB(A a, B b, MappingContext context) {
			if (StringUtils.isNotEmpty(a.getStringA())) {
				BSetElement bElem = new BSetElement();
				bElem.setStringB(a.getStringA());
				b.getElementsSet().add(bElem);
			}
		}
	})
	.register();
A a = new A();
a.setStringA("test");

B b = mapperFactory.getMapperFacade().map(a, B.class);

assertThat(b.getElementsSet(), hasSize(1));
assertThat(b.getElementsSet().iterator().next().getStringB(), is("test"));

Here is the TestCase I used:
Issue104TestCase.java.txt

from orika.

ndr-brt avatar ndr-brt commented on July 19, 2024

Agree with @brabenetz

from orika.

ndr-brt avatar ndr-brt commented on July 19, 2024

Fixed by #180

from orika.

Related Issues (20)

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.