Global setting in Mapstruct to trim string values

3,002 views
Skip to first unread message

Venkat Srinivasan

unread,
Aug 1, 2016, 12:15:50 PM8/1/16
to mapstruct-users
Hi,

Is there a global setting n MapStruct that one can use to trim string values.

Dozer offers such a facility through its mapping configuration, for example,


<configuration>
    <trim-strings>true</trim-strings>
</configuration>


Also see Dozer Global Configuration


With MapStruct 1.0.0.Final I can achieve this through Expressions or Before/After Mapping customization.

But wanted to know if there is a better way to handle such use cases.


Thanks in advance.


I had raised this question in StackOverflow  not realising this group is active.

Thanks
Venkat

Andreas Gudian

unread,
Aug 1, 2016, 2:44:00 PM8/1/16
to Venkat Srinivasan, mapstruct-users
Hi Venkat,

We don't have that at the moment. But you can use implement a custom method to donthe trimming, e.g.:

String trimmed(String s) { return s != null ? s.trim() : null; }

If you want only some String properties to be trimmed, just add a qualifier Annotation to that method (you could call it @Trimmed or something). See the reference docs for an example how to do it. (I'm on my phone here only, so pardon my formatting)

Andreas


--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Venkat Srinivasan

unread,
Aug 2, 2016, 4:27:19 AM8/2/16
to mapstruct-users, raghav...@gmail.com, mapstru...@googlegroups.com
Hello Andreas,

Thanks for reverting back.Clearly I over looked these aspects in the documentation. 
Either of them will help the use case I am dealing with. 

Cheers
Venkat

On Monday, 1 August 2016 19:44:00 UTC+1, Andreas Gudian wrote:
Hi Venkat,

We don't have that at the moment. But you can use implement a custom method to donthe trimming, e.g.:

String trimmed(String s) { return s != null ? s.trim() : null; }

If you want only some String properties to be trimmed, just add a qualifier Annotation to that method (you could call it @Trimmed or something). See the reference docs for an example how to do it. (I'm on my phone here only, so pardon my formatting)

Andreas


Am Montag, 1. August 2016 schrieb Venkat Srinivasan :
Hi,

Is there a global setting n MapStruct that one can use to trim string values.

Dozer offers such a facility through its mapping configuration, for example,


<configuration>
    <trim-strings>true</trim-strings>
</configuration>


Also see Dozer Global Configuration


With MapStruct 1.0.0.Final I can achieve this through Expressions or Before/After Mapping customization.

But wanted to know if there is a better way to handle such use cases.


Thanks in advance.


I had raised this question in StackOverflow  not realising this group is active.

Thanks
Venkat

--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages