Coder Social home page Coder Social logo

Comments (21)

uguy avatar uguy commented on June 4, 2024 18

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.

igorbljahhin avatar igorbljahhin commented on June 4, 2024 8

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.

simasch avatar simasch commented on June 4, 2024 5

Run into the same problem today. Hope this will be fixed soon

from spring-cloud-openfeign.

 avatar commented on June 4, 2024 3

+1

from spring-cloud-openfeign.

fabmars avatar fabmars commented on June 4, 2024 2

Yes it does! Working here on the latest SpringBoot 1.4.2

from spring-cloud-openfeign.

michaeltecourt avatar michaeltecourt commented on June 4, 2024 1

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.

michaeltecourt avatar michaeltecourt commented on June 4, 2024 1

@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.

Mintas avatar Mintas commented on June 4, 2024 1

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.

spencergibb avatar spencergibb commented on June 4, 2024

@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.

uguy avatar uguy commented on June 4, 2024

@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.

fabmars avatar fabmars commented on June 4, 2024

Sorry for not responding earlier.
@spencergibb that was https://jira.spring.io/browse/DATAREST-851
@uguy 100% agreed

from spring-cloud-openfeign.

m190 avatar m190 commented on June 4, 2024

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.

innokenty avatar innokenty commented on June 4, 2024

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.

MrSummer33 avatar MrSummer33 commented on June 4, 2024

@spencergibb can i put my localDate field in ResquestBody?

from spring-cloud-openfeign.

willpewitt avatar willpewitt commented on June 4, 2024

Any resolution on this?

from spring-cloud-openfeign.

ryanjbaxter avatar ryanjbaxter commented on June 4, 2024

If there was it would have been closed

from spring-cloud-openfeign.

CH-jakegale avatar CH-jakegale commented on June 4, 2024

+1 on finding this issue. Expander is ignoring DateTime formats.
Adding @uguy 's bean fixes the issue.

from spring-cloud-openfeign.

Mintas avatar Mintas commented on June 4, 2024

Hello, everybody!
Looks, like you are missing one of this ultrauseful thing, provided mostly by spring:

  1. org.springframework.cloud.openfeign.FeignClientsConfiguration.class - will autoconfigure decoders/encoders with lookup to other beans for serialization/deserialization
  2. org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration - will autoconfigure jackson/gson/json message converters, used with spring boot anf feign internally
  3. 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.

fabmars avatar fabmars commented on June 4, 2024

And do you have a solution to propose that's better than @uguy 's ?

from spring-cloud-openfeign.

rafaelfbs avatar rafaelfbs commented on June 4, 2024

#47

from spring-cloud-openfeign.

OlgaMaciaszek avatar OlgaMaciaszek commented on June 4, 2024

Fixed with #47.

from spring-cloud-openfeign.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.