Announcement Announcement Module
Collapse
No announcement yet.
Encoding problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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();

      Comment


      • #4
        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.

        Comment

        Working...
        X