How to remove leading and trailing white spaces from String attributes of Immutable Objects

667 views
Skip to first unread message

Gautam Priya

unread,
Jun 7, 2017, 4:54:40 PM6/7/17
to guava-discuss
I need to ensure that all String attributes of immutable objects (guava Immutables) have no leading and trailing white spaces. Immutable objects are created to represent RESTful API requests. I would like to do better than reject the request when the String attributes contain leading and/or trailing white spaces in the @Value.check method using Precondition.checks. I want to remove the white spaces in the incoming request's String fields when creating the Immutable objects. If that is not possible to do by appropriately styling the Builder (I believe that today this is not possible), then is it possible to re-set the values in the value.check method or by some other means?

Louis Wasserman

unread,
Jun 7, 2017, 5:01:21 PM6/7/17
to Gautam Priya, guava-discuss
I'm not certain, but it sounds like you're referring to https://immutables.github.io/immutable.html, which is a completely separate project from Guava and not associated with this mailing list. 

If that's the case, you should contact that project's mailing list, which appears to be at https://groups.google.com/forum/#!forum/immutables .  Hopefully they can help you?

On Wed, Jun 7, 2017 at 1:54 PM Gautam Priya <gautam...@gmail.com> wrote:
I need to ensure that all String attributes of immutable objects (guava Immutables) have no leading and trailing white spaces. Immutable objects are created to represent RESTful API requests. I would like to do better than reject the request when the String attributes contain leading and/or trailing white spaces in the @Value.check method using Precondition.checks. I want to remove the white spaces in the incoming request's String fields when creating the Immutable objects. If that is not possible to do by appropriately styling the Builder (I believe that today this is not possible), then is it possible to re-set the values in the value.check method or by some other means?

--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/4f8245ca-b1e3-484e-8d45-b1565de6466f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Catherine Berry

unread,
Jun 7, 2017, 5:03:36 PM6/7/17
to Gautam Priya, guava-discuss
If you'e pulling the Strings out of some request object and building an immutable data structure from them, can't you trim each of them in the process? Similarly, if untrimmed Strings are valid input, shouldn't your validator just accept them as is?

On Wed, Jun 7, 2017 at 1:54 PM, Gautam Priya <gautam...@gmail.com> wrote:
I need to ensure that all String attributes of immutable objects (guava Immutables) have no leading and trailing white spaces. Immutable objects are created to represent RESTful API requests. I would like to do better than reject the request when the String attributes contain leading and/or trailing white spaces in the @Value.check method using Precondition.checks. I want to remove the white spaces in the incoming request's String fields when creating the Immutable objects. If that is not possible to do by appropriately styling the Builder (I believe that today this is not possible), then is it possible to re-set the values in the value.check method or by some other means?

--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discuss+unsubscribe@googlegroups.com.



--
"Easy things should be easy, and hard things should be possible." - Larry Wall
Catherine Berry (go/cberry-name)
Software Engineer
Google Los Angeles

Gautam Priya

unread,
Jun 7, 2017, 7:11:44 PM6/7/17
to guava-discuss, gautam...@gmail.com
Thanks for pointing me to the appropriate group. Appreciated.

Gautam Priya

unread,
Jun 7, 2017, 7:14:12 PM6/7/17
to guava-discuss, gautam...@gmail.com
I could try to write a custom Deserializer for Jackson and see the ObjectMapper with it to affect Jackson's deserialization so that String fields in request objects are stripped of white space. That said, I was trying to if there was some way to do this during or after Immutable object creation but before it is returned to the caller.


On Wednesday, June 7, 2017 at 2:03:36 PM UTC-7, Craig Berry wrote:
If you'e pulling the Strings out of some request object and building an immutable data structure from them, can't you trim each of them in the process? Similarly, if untrimmed Strings are valid input, shouldn't your validator just accept them as is?
On Wed, Jun 7, 2017 at 1:54 PM, Gautam Priya <gautam...@gmail.com> wrote:
I need to ensure that all String attributes of immutable objects (guava Immutables) have no leading and trailing white spaces. Immutable objects are created to represent RESTful API requests. I would like to do better than reject the request when the String attributes contain leading and/or trailing white spaces in the @Value.check method using Precondition.checks. I want to remove the white spaces in the incoming request's String fields when creating the Immutable objects. If that is not possible to do by appropriately styling the Builder (I believe that today this is not possible), then is it possible to re-set the values in the value.check method or by some other means?

--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages