Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

How to customize the date type serializer #106

@houkunlin

Description

@houkunlin

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions