micronaut-projects / micronaut-spring

A collection of utilities for Spring users of Micronaut
Apache License 2.0
165 stars 46 forks source link

formatters are not utilized #4

Open rburgst opened 6 years ago

rburgst commented 6 years ago

Custom formatters are not available: See

https://github.com/rburgst/micronaut-spring-example

The gist ist that you would define custom type converters for REST controller methods via the FormatterRegistry

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatterForFieldType(TenantId.class, 
          new GenericIdFormatter(TenantId.class));
    }
}

These are not used/initialized by micronaut-spring, therefore the following request fails:

$ http ":8080/greet?tenantId=7364b7d8-490d-49b9-8e18-7b96f41734e8"

HTTP/1.1 400 Bad Request
Date: Sun, 2 Dec 2018 09:16:43 GMT
connection: close
content-length: 184
content-type: application/json

{
    "_links": {
        "self": {
            "href": "/greet?tenantId=7364b7d8-490d-49b9-8e18-7b96f41734e8",
            "templated": false
        }
    },
    "message": "Required argument [TenantId tenantId] not specified",
    "path": "/tenantId"
}

To replicate the problem, launch the application via

./gradlew bootRun

and send the above mentioned request.

graemerocher commented 5 years ago

I guess we could probably adapt formatters to the binder API, will see what we can do. Thanks for the feedback