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.

Rest template error with custom converter #2088

Description

I'm not entirely sure if this is an error with Spring or AA, but hopefully there's a fix for this.
The issue I'm having is that I want to replace FormHttpMessageConverter with a custom one, my code is this:

public class CustomFormHttpMessageConverter extends FormHttpMessageConverter
{
    public CustomFormHttpMessageConverter()
    {
        List<MediaType> supportedMediaTypes = new ArrayList<>(getSupportedMediaTypes());
        supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
        supportedMediaTypes.add(MediaType.MULTIPART_FORM_DATA);
        setSupportedMediaTypes(supportedMediaTypes);

        List<HttpMessageConverter<?>> partConverters = new ArrayList<>();
        partConverters.add(new ByteArrayHttpMessageConverter());
        StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        stringHttpMessageConverter.setWriteAcceptCharset(false);
        partConverters.add(stringHttpMessageConverter);
        partConverters.add(new ResourceHttpMessageConverter());
        setPartConverters(partConverters);
    }
}

But when compiling with these options for the rest template

@Rest(converters = {CustomFormHttpMessageConverter.class, MappingJackson2HttpMessageConverter.class, StringHttpMessageConverter.class},
        rootUrl = BuildConfig.backendURL,
        interceptors = {HeaderRequestInterceptor.class},
        requestFactory = CustomHttpRequestFactory.class)

The attached errors from the stacktrace happens, the only way I get this to work is to add the standard FormHttpMessageConverter after my custom one, then it's working as intended.

AndroidAnnotations version:
4.4.0
Android compile SDK version:
26

Stacktrace in case of AA crash:

13:44:59.335 [Task worker for ':'] WARN  o.a.i.p.ModelValidator:88 - Element note invalidated by FieldHandler
13:44:59.335 [Task worker for ':'] ERROR o.a.i.p.ModelValidator:77 - org.androidannotations.rest.spring.annotations.Field annotated method parameter must be in a @Rest annotated interface which uses at least one org.springframework.http.converter.FormHttpMessageConverter (or subtype)

Activity

  1. dodgex commented on Nov 28, 2017

    @dodgex
    Member

    Yeah. Looks like a bug in RestSpringValidatorHelper as the parameters are in wrong order.

  2. dodgex commented on Nov 28, 2017

    @dodgex
    Member

    I've openend a PR that should fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions