Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to customize the date type serializer #106

Open
houkunlin opened this issue Jan 6, 2022 · 0 comments
Open

How to customize the date type serializer #106

houkunlin opened this issue Jan 6, 2022 · 0 comments

Comments

@houkunlin
Copy link

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

new UrlencodedFormContentProcessor()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant