Results 1 to 4 of 4

Thread: Encoding problem

  1. #1
    Join Date
    Jul 2010
    Posts
    3

    Default Encoding problem

    Hi.
    Both twitter and facebook use default RestTemplate object configured with FormHttpMessageConverter. The default encoding for this converter is set to "ISO-8859-1", though UTF-8 should be used with Facebook and Twitter API.

    Looks like a bug. I've overridden template constructors as a workaround:
    Code:
    List<HttpMessageConverter<?>> converters = getRestTemplate().getMessageConverters();
            for (HttpMessageConverter<?> converter : converters) {
                if (converter instanceof FormHttpMessageConverter) {
                    ((FormHttpMessageConverter) converter).setCharset(Charset.forName("UTF8"));
                }
    			if(converter instanceof MappingJacksonHttpMessageConverter) {
    				MappingJacksonHttpMessageConverter jsonConverter = (MappingJacksonHttpMessageConverter) converter;
    				ObjectMapper objectMapper = new ObjectMapper();
    				objectMapper.registerModule(new FacebookModule());
                    objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    				jsonConverter.setObjectMapper(objectMapper);
    			}
    		}
    probably there is a better solution?

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    We should definitely fix this issue if its a bug. What specific problems were occurring in your application that led you to notice this issue? Just curious.
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Jul 2010
    Posts
    3

    Default

    I use russian to post to Facebook and Twitter so my messages turned into something like:
    ?? ?????? hello world
    Specifically for these methods:
    facebookConnection.getApi().feedOperations().postL ink();
    timelineOperations.updateStatus();

  4. #4
    Join Date
    Aug 2004
    Posts
    1,070

    Default

    It looks like this is a bug when used with Spring 3.0.x. In Spring 3.1, UTF-8 is FormHttpMessageConverter's default character set, so it works fine. But in Spring 3.0.x, it defaults to ISO-8859-1, which is where you're probably seeing the problem.

    This was corrected in SPR-7789, but that fix doesn't appear in any released 3.0.x build.

    I've created https://jira.springsource.org/browse/SOCIAL-170 to address this in Spring Social.
    Craig Walls
    Spring Social Project Lead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •