Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping immutable types #216 #218

Merged
merged 7 commits into from
Nov 29, 2017
Merged

Conversation

piotrdytkowski
Copy link
Contributor

Allows to use no-args constructor to create immutable objects

@garethahealy
Copy link
Collaborator

@piotrdytkowski ; can you rebase with latest to force travis to retest

@garethahealy
Copy link
Collaborator

@piotrdytkowski ; any update?

@piotrdytkowski
Copy link
Contributor Author

Hey, sure, will have a look later. I don't like the name 'omit-constructor' anymore though...

@garethahealy
Copy link
Collaborator

@piotrdytkowski ; have you had anytime to progress?

@piotrdytkowski
Copy link
Contributor Author

piotrdytkowski commented Jun 27, 2017

Hey, I rebased the project, but now have a test failing (VariablesTest) in maven but passing in my IDE, must be something with deps or environment. I hope to sort it out soon.

@piotrdytkowski
Copy link
Contributor Author

piotrdytkowski commented Jun 27, 2017

Now I see that master branch CI is failing for the same reason. I will update when you fix/revert master.

@garethahealy
Copy link
Collaborator

@piotrdytkowski ; master branch has now been fixed. Can you rebase.

@piotrdytkowski
Copy link
Contributor Author

piotrdytkowski commented Jul 5, 2017

I rebased but got some osgi tests failing, they seem unrelated but I can be wrong. Can you help me with this?

Tests in error: 
  OsgiContainerTest.shouldInstantiate:59 » ClassNotFound org.dozer.DozerBeanMapp...
  OsgiContainerTest.shouldLoadMappingFile:72 » ClassNotFound org.dozer.DozerBean...
  OsgiContainerTest.shouldMap:65 » ClassNotFound org.dozer.DozerBeanMapperBuilde...

@piotrdytkowski
Copy link
Contributor Author

Hey @garethahealy , did you have any time to look at this?

@garethahealy
Copy link
Collaborator

@piotrdytkowski ; no sorry, am currently on holiday, so might be a few weeks.

core/pom.xml Outdated
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.12</version>
</dependency>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

junit isnt required. It comes from the parent pom, as per:

core/pom.xml Outdated
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.20</version>
</dependency>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What uses this dep? Cant see why its needed.

schema/pom.xml Outdated
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.20</version>
</dependency>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment. Why are these 2 needed?

@garethahealy
Copy link
Collaborator

@piotrdytkowski ; the OSGi test are failing as you've added a new dependancy: org.objenesis.

It needs to be added as a required dependancy in the OSGi tests:

@piotrdytkowski
Copy link
Contributor Author

dozer-osgi-tests has a dependency on dozer-core so it should pull objenesis just fine. I rebased again and removed test libs added before. Hope to merge it soon 🍾

@garethahealy
Copy link
Collaborator

Like i said, you need to add the new dep to the OSGi container. Since my last comment, this has slightly changed, but if you look at:

You'll see all the core deps needed. Those "link" URLS come from build time in:

  • target/generated-test-resources/alta/

@piotrdytkowski
Copy link
Contributor Author

Great, that's what I needed. Thanks :)

@piotrdytkowski
Copy link
Contributor Author

Build is green.

@dmitrySDK
Copy link

dmitrySDK commented Nov 17, 2017

Hi! I think it is great functionality, but I cannot find a way to configure skipConstructor without XML, that is only with API. Is that possible with current code or (if not) maybe it should be a different PR?

BR
Dmitry Sherstnyakov

@piotrdytkowski
Copy link
Contributor Author

I didn't have a look at the api, back in 2014 when I implemented it maybe api configuration didn't even exist :D
I would suggest to get it merged and then build on top of it. Maybe I'll do it when I have some free time.

core/pom.xml Outdated
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.6</version>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this to the dependancyManagement section of the bom

@garethahealy
Copy link
Collaborator

CC @orange-buffalo

@garethahealy
Copy link
Collaborator

Looks fine from my point of view.

Copy link
Contributor

@orange-buffalo orange-buffalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piotrdytkowski It would be great to extend the documentation (see docs/asciidoc/documentation) with new feature description and example.

@garethahealy with objenesis dependency added, Dozer now pulls quite some list of dependencies into user's projects. Probably we should think about improvement here. Maybe creating one single uber jar with shaded dependencies could be an option..

return skipConstructor != null && skipConstructor;
}

public void setSkipConstructor(Boolean omitConstructor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to rename the method parameter to match the property name.

@@ -511,6 +511,10 @@ public void mapEmptyString(Boolean value) {
public void isAccessible(Boolean value) {
definition.setAccessible(value);
}

public void isSkipConstructor(Boolean skipConstructor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to rename this method to skipConstructor as it reflects the underlying configuration option more accurately.

}

private <T> T newInstance(Class<T> clazz) {
ObjectInstantiator<T> instantiator = objectFactory.getInstantiatorOf(clazz);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we are not loosing the semantics here. According to the javadocs, org.objenesis.Objenesis#getInstantiatorOf:

Will pick the best instantiator for the provided class

Which includes constructor instantiator if constructor is provided for the target class.

As we rely on parameter skip-constructor, users would expect that their constructors will never be invoked. Thus it makes sense to use org.objenesis.Objenesis#newInstance, as it:

Will create a new object without any constructor being called

@piotrdytkowski
Copy link
Contributor Author

Review the changes, please. I had to make that last commit to retrigger the build, because it ... randomly failed. Thanks for the feedback, good spot with the ObjectInstantiator. Thanks 👍

Copy link
Contributor

@orange-buffalo orange-buffalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piotrdytkowski Thanks for the update!
Looks good to me.

@garethahealy garethahealy merged commit c87c5dc into DozerMapper:master Nov 29, 2017
CyberClems pushed a commit to CyberClems/dozer that referenced this pull request Mar 18, 2019
garethahealy pushed a commit that referenced this pull request Apr 18, 2019
* Add missing skipConstructor method to API (#218)

* Fix checkstyle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants