Comments (21)
It look s like when the Feign expander is called, it has no info on the @DateTimeFormat
annotation (or any other ?) so no ways to apply custom conversion ?
ReflectiveFeign, line 205 :
value = indexToExpander.get(i).expand(value);
Then Spring Expander call the conversion service to get a String representation of the value.
Applying ISO DATE format to all feign cliens as default is workaround to format date but not a fix :
@Bean
public FeignFormatterRegistrar localDateFeignFormatterRegistrar() {
return new FeignFormatterRegistrar() {
@Override
public void registerFormatters(FormatterRegistry formatterRegistry) {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(formatterRegistry);
}
};
}
from spring-cloud-openfeign.
Same issue here. Feign version is 9.3.1, Spring Cloud 1.2.6
Feign client is following:
@FeignClient(name = "pricing-service", url = "${modules.pricing.url}")
public interface SailPricesResource {
@RequestMapping(value = "/api/v1/prices/{date}/{time}", method = RequestMethod.GET)
GetSailPricesResponseDTO getSailPricesForDeparture(final @PathVariable("date") LocalDate date, final @PathVariable("time") LocalTime time);
}
The date gets formatted as "D/M/YY" and time gets formatted as "hh:mm a", although there are custom converters defined in
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new LocalDateToStringConverter());
registry.addConverter(new StringToLocalDateConverter());
registry.addConverter(new LocalTimeToStringConverter());
registry.addConverter(new StringToLocalTimeConverter());
registry.addConverter(new LocalDateTimeToStringConverter());
registry.addConverter(new StringToLocalDateTimeConverter());
}
}
After debugging I discovered that Feigh clients are created before the conversion service is updated with my custom converters. The issue has gone only after I added
@Configuration
public class FeignConfiguration {
@Bean
public Contract feignContract() {
return new SpringMvcContract();
}
}
from spring-cloud-openfeign.
Run into the same problem today. Hope this will be fixed soon
from spring-cloud-openfeign.
+1
from spring-cloud-openfeign.
Yes it does! Working here on the latest SpringBoot 1.4.2
from spring-cloud-openfeign.
I confirm, the @DateTimeFormat
annotation is completely ignored, no matter the type used : LocalDate
, OffsetDateTime
, LocalDateTime
...
@uguy's workaround (thank you BTW) can also be used with JodaTime using org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar
instead of org.springframework.format.datetime.standard.DateTimeFormatterRegistrar
.
Both tools can be initialized in the registerFormatters
method if needed.
from spring-cloud-openfeign.
@spencergibb it would be cool if the client side behavior of @DateTimeFormat
matched the server side :
@FeignClient(name = "data-api", url = "http://example.com")
public interface DataApiClient {
@RequestMapping(value = "/api/data", method = RequestMethod.GET)
Data getData(@DateTimeFormat(iso = ISO.DATE_TIME) @RequestParam("from") OffsetDateTime from,
@DateTimeFormat(pattern = "yyyy-MM") @RequestParam("to") OffsetDateTime to);
}
I would expect the example above to create the following URL :
http://example.com/api/data?from=2016-09-15T00:00:00.000Z&to=2016-09
from spring-cloud-openfeign.
You know, that solution is really very very outdated, and all this features are autoconfigured this days, anyway, you can combine both. ( you can inspect sources of classes mentioned above and find out am telling the truth)
Just have to note, that @uguy solution didn't help at our case at all =( #104 (comment)
And one more thing: it will not work without JSR310 dependency.
BTW, this is good, because it shows you, how to add additional configurations or how to proceed if you do not use autoconfigurations at all... but who doesnt? =)
UPD: we use
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.1.RELEASE"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.M3"
}
}
from spring-cloud-openfeign.
@fabmars can you put the spring issue link here?
@uguy @michaeltecourt how do you think a solution from us might behave?
from spring-cloud-openfeign.
@spencergibb Same for me. The closer the client contract expressed is from the server contract, the better. But I do not know how to do this right now (need to look a bit further in the code).
It could be linked to another issue which seems to be also related to annotation parsing/handling : spring-cloud/spring-cloud-netflix#867
Maybe a generic solution could be found ?
from spring-cloud-openfeign.
Sorry for not responding earlier.
@spencergibb that was https://jira.spring.io/browse/DATAREST-851
@uguy 100% agreed
from spring-cloud-openfeign.
Are there any way how to make custom date format now?
I tried to use the list of date and neither approach is working. I have such a client
@FeignClient(name = "exampleClient", url = "#{EXAMPLE_URL}" )
public interface ExampleClient{
@RequestMapping(value = "/example", method = RequestMethod.GET)
String getExampleValue(@RequestParam(name = "date") List<Date> dates);
}
And I couldn't find any way how to format the date. I think it's partially because of the spring-cloud/spring-cloud-netflix#1115 fix. The extender is not appends, and no formatter is used,
from spring-cloud-openfeign.
Does the workaround with the registrar posted above work for anyone? I still bget this annotation totally ignored. I'm using Joda LocaDate
, but switching to Joda registrar doesn't change anything. Is there something else I need to add maybe?
from spring-cloud-openfeign.
@spencergibb can i put my localDate field in ResquestBody?
from spring-cloud-openfeign.
Any resolution on this?
from spring-cloud-openfeign.
If there was it would have been closed
from spring-cloud-openfeign.
+1 on finding this issue. Expander is ignoring DateTime formats.
Adding @uguy 's bean fixes the issue.
from spring-cloud-openfeign.
Hello, everybody!
Looks, like you are missing one of this ultrauseful thing, provided mostly by spring:
- org.springframework.cloud.openfeign.FeignClientsConfiguration.class - will autoconfigure decoders/encoders with lookup to other beans for serialization/deserialization
- org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration - will autoconfigure jackson/gson/json message converters, used with spring boot anf feign internally
- com.fasterxml.jackson.datatype:jackson-datatype-jsr310 - be sure you have properly included this library dependency to your classpath. It gives you JavaTimeModule for ObjectMapper, without this feature all your solutions will not work.
from spring-cloud-openfeign.
And do you have a solution to propose that's better than @uguy 's ?
from spring-cloud-openfeign.
from spring-cloud-openfeign.
Fixed with #47.
from spring-cloud-openfeign.
Related Issues (20)
- Default request header headers overwriten with specific client configuration and shared by all clients HOT 1
- PlaytikaOSS feign-reactive does not support spring boot 3.2.x HOT 1
- @PatchMapping and @DeleteMapping insert unwanted slash when using url and specific value HOT 3
- FeignClientFactoryBean dismiss404 default config overrides client-specific config HOT 1
- Multiple implementations of ResponseInterceptor fail to trigger HOT 10
- Want to understand , is Spring Openfeign is in Deprecated path HOT 1
- Maintain the span from HTTP calls using feign clients with micrometer HOT 1
- Micrometer tracing propagation not working when using Spring FactoryBean and Feign HOT 1
- Custom HTTP codes are not supported HOT 1
- B3 span and parentId headers not propagated with spring-cloud-openfeign and brave HOT 1
- Remove unused spring-boot-starter-aop dependency HOT 1
- [sentinel] openfeign+sentinel Error HOT 2
- Spring Boot 3.2.4 (Cloud 2023.0.1) Cannot deserialize "pageable": "INSTANCE" HOT 5
- Issue with registering method parameter hints HOT 3
- Headers annotation not sending headers HOT 2
- Upgrade to fileupload2 HOT 6
- IllegalArgumentException due to null servletRequest for Oauth2AccessTokenInterceptor after Spring Cloud Update HOT 3
- Fallback functionality should be selectively enabled depending on the actual presense of fallback implementation HOT 1
- provide ignore annotation to programmatically ignore method parameter HOT 1
- Support customization of JDK 11+ HttpClient
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-cloud-openfeign.