This repository was archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Rest template error with custom converter #2088
Copy link
Copy link
Closed
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)
Metadata
Metadata
Assignees
Labels
No labels