feign-form icon indicating copy to clipboard operation
feign-form copied to clipboard

How to customize the date type serializer

Open houkunlin opened this issue 2 years ago • 0 comments

How to customize the date type serializer

@PostMapping(value = "uri", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
String request(@RequestBody DataForm form);
@Data
public class DataForm implements Serializable {
    /**
     * start time eg: 2018-01-01 06:00:00
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sd;
    /**
     * end time eg: 2018-01-01 21:00:00
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime ed;
}

---> POST https://httpreq.com/small-block-yri972hg/record/ HTTP/1.1
Content-Length: 113
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
ed=2022-01-30T00%3A00&sd=2021-12-01T00%3A00
---> END HTTP (113-byte body)

Interfacing with third-party websites, the request body type cannot be changed

The above request will be executed to feign.form.UrlencodedFormContentProcessor#encode here to process POJO field value, If the field value is of Date/LocalDate/LocalDateTime type, the expected value cannot be obtained, I want a custom date type serializer.

I want to customize this UrlencodedFormContentProcessor object to support serialized date objects, how to do it

https://github.com/OpenFeign/feign-form/blob/98e51d187f1b7acba3b39d1131371b761d87259b/feign-form/src/main/java/feign/form/FormEncoder.java?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L75

houkunlin avatar Jan 06 '22 05:01 houkunlin