Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Providing MessageConverter for RestTemplate #206

Description

@pyricau

@royclarkson just let me know that the RestTemplate default constructor now comes with no MessageConverters, for performance reasons.

It's quite obvious that no one needs all the default converters, we usually only need one converter.

This change also means that by default, a @Rest annotated interface will come with en empty RestTemplate that will have no MessageConverter. To add one, we must do: restClient.getRestTemplate().getMessageConverters().add(new MappingJacksonHttpMessageConverter());

We should provide a new annotation (or a new attribute) to let users specify the MessageConverters.

@Rest 
@Converters({MappingJacksonHttpMessageConverter.class, XmlAwareFormHttpMessageConverter.class})
public interface RestClient {
}

We should check that they have a default constructor. We could also allow classes annotated with @EBean, but I'm not sure this would provide much added value for now.

Activity

  1. royclarkson commented on May 25, 2012

    @royclarkson
    Contributor

    It is still possible to create a new RestTemplate instance with the default set of converters by calling RestTemplate(true). As you note, there isn't a lot of need for loading all of these though. For reference, these are the default converters that are loaded:

    • ByteArrayHttpMessageConverter - Always included
    • StringHttpMessageConverter - Always included
    • ResourceHttpMessageConverter - Always included
    • SourceHttpMessageConverter - Included on Android 2.2 (Froyo) or newer, where javax.xml.transform.Source is available
    • XmlAwareFormHttpMessageConverter - same as previous
    • FormHttpMessageConverter - Included on Android 2.1 (Eclair) and older
    • SimpleXmlHttpMessageConverter - Included if the Simple XML serializer is present
    • MappingJacksonHttpMessageConverter - Included if the Jackson JSON processor is present
    • SyndFeedHttpMessageConverter - Included if the Android ROME Feed Reader is present
  2. pyricau commented on May 26, 2012

    @pyricau
    ContributorAuthor

    Thank your for those details. We could also detect the availability of the libs in the classpath at compile time and automatically add the converters in such a case, but I think we'd rather let the users fail early, find out that they need to add specific converters & libs, and then only add the needed ones.

    I added a RestTemplate section to the documentation to document this new RestTemplate behavior. Thanks again for letting us know!

  3. a-thomas commented on May 31, 2012

    @a-thomas
    Contributor

    We can let the two ways:

    1. The users don't specify @Converters, then we use the default RestTemplate constructor
    2. They specify @Converters, then we add the provided ones.
  4. pyricau commented on May 31, 2012

    @pyricau
    ContributorAuthor

    Well, since the default RestTemplate constructor is now the one that comes with no converters, there's no "two ways" here :) . They'll both use the same constructor.

  5. added a commit that references this issue on Nov 4, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions