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

Allow defaultValue to be an expression #1363

Closed
smythie86 opened this Issue Dec 27, 2017 · 8 comments

Comments

Projects
None yet
4 participants
@smythie86
Copy link
Contributor

smythie86 commented Dec 27, 2017

It would be great to be able to make an expression a default value, like this:

    @Mappings({
      @Mapping(target="Id", source="obj.SourceId", defaultValue = "java(UUID.randomUUID().toString())")
    })
    MyObject myObjToMyObject(MyObj obj);

@filiphr filiphr added this to the Future planning milestone Dec 31, 2017

@filiphr filiphr added the feature label Dec 31, 2017

@filiphr

This comment has been minimized.

Copy link
Member

filiphr commented Dec 31, 2017

That's an interesting proposal @smythie86. I am not sure if we should reuse defaultValue or add a new defaultExpression for this. The advantage of adding a new defaultExpression would be in the fact that it would be much clearer to the person looking at the code

@sjaakd

This comment has been minimized.

Copy link
Contributor

sjaakd commented Dec 31, 2017

@gunnarmorling

This comment has been minimized.

Copy link
Member

gunnarmorling commented Dec 31, 2017

Why is it that not simply the existing expression() could be used? Is it related to the case where the source property is null?

@filiphr

This comment has been minimized.

Copy link
Member

filiphr commented Dec 31, 2017

@sjaakd that was the proposal of @smythie86.

@gunnarmorling yes this is when the source is null, we can't use the current expression as that is for the actual mapping of the property. That is why I suggested the defaultExpression. However, we could reuse the defaultValue as well.

@gunnarmorling

This comment has been minimized.

Copy link
Member

gunnarmorling commented Dec 31, 2017

@filiphr

This comment has been minimized.

Copy link
Member

filiphr commented Jan 1, 2018

I personally am split, I have no particular preference between reusing defaultValue and adding a new one.

@smythie86 if you are interested you can provide a PR for this functionality, we can of course help you out with it ;)

@smythie86

This comment has been minimized.

Copy link
Contributor Author

smythie86 commented Jan 19, 2018

I will try to take a look at this and see what I can do

@filiphr filiphr modified the milestones: Future planning, 1.3.x Feb 11, 2018

filiphr added a commit that referenced this issue Feb 19, 2018

@filiphr

This comment has been minimized.

Copy link
Member

filiphr commented Feb 19, 2018

Support for this has been added in #1372 thanks for the PR @smythie86, sorry that it took so long to merge it

@filiphr filiphr closed this Feb 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.