Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:14:48+00:00 2026-05-24T09:14:48+00:00

Example JSON (note that the string has trailing spaces): { aNumber: 0, aString: string

  • 0

Example JSON (note that the string has trailing spaces):

{ "aNumber": 0, "aString": "string   " }

Ideally, the deserialised instance would have an aString property with a value of “string” (i.e. without trailing spaces). This seems like something that is probably supported but I can’t find it (e.g. in DeserializationConfig.Feature).

We’re using Spring MVC 3.x so a Spring-based solution would also be fine.

I tried configuring Spring’s WebDataBinder based on a suggestion in a forum post but it does not seem to work when using a Jackson message converter:

@InitBinder
public void initBinder( WebDataBinder binder )
{
    binder.registerCustomEditor( String.class, new StringTrimmerEditor( " \t\r\n\f", true ) );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:14:49+00:00Added an answer on May 24, 2026 at 9:14 am

    With a custom deserializer, you could do the following:

     <your bean>
     @JsonDeserialize(using=WhiteSpaceRemovalSerializer.class)
     public void setAString(String aString) {
        // body
     }
    
     <somewhere>
     public class WhiteSpaceRemovalDeserializer extends JsonDeserializer<String> {
         @Override
         public String deserialize(JsonParser jp, DeserializationContext ctxt) {
             // This is where you can deserialize your value the way you want.
             // Don't know if the following expression is correct, this is just an idea.
             return jp.getCurrentToken().asText().trim();
         }
     }
    

    This solution does imply that this bean attribute will always be serialized this way, and you will have to annotate every attribute that you want to be deserialized this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, here's a 'page': http://www.facebook.com/facebook That page has an RSS feed (which I'd
I have data that I convert to JSON. I need storage to be very
I have this example where I am trying to access json value, but it
The below example shows how I'm building the query string that will return a
I'm working on simple Haskell programme that fetches a JSON string from a server,
This is a general question. Using an example below, suppose that I have a
When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from
In the example for coding with Json using Databinder Dispatch Nathan uses an Object
Why should I use JSON with ASP.NET? Can you give a practical example? I
Trying to get a JSON output to work with jqGrid 'userdata' option. The example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.