spring-cloud / spring-cloud/spring-cloud-gateway

ModifyResponseBody serialize Dates as timestamp

Open
#2,758 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

For using RouteLocatorBuilder to modifyResponseBody returns dates as timestamp.
I am using write-dates-as-timestamp=false and it works for other API endpoint or for bean ObjecMapper. I can not solve that problem. I check the samples but there is simple String to String modifying response body.

Sample
It is route definition

.route(
            "responseSchedule",
            predicateSpec ->
                predicateSpec
                    .path("/schedules/**")
                    .and()
                    .method(GET, POST, PUT, DELETE)
                    .filters(this::applyTest)
                    .uri(schedulerUrl))

Which use rewriteFuntcion:

private UriSpec applyTest(GatewayFilterSpec f) {
    return f.modifyResponseBody(
        StackScheduleResponse.class,
        ScheduleResponse.class,
        MediaType.APPLICATION_JSON_VALUE,
        parseResponse());
  }

private RewriteFunction<StackScheduleResponse, ScheduleResponse> parseResponse() {
    return (serverWebExchange, s) -> Mono.just(map(s));
  }

map method simply map one object on another, but the response from gateway is like below, but "time" properties are as timestamp, properties are defined as OffsetDateTime:

{
	"name": "report",
	"action": null,
	"schedule_type": "monthly",
	"start_time": 1593455160.000000000,
	"end_time": 1666343280.253480200,
	"next_run": null,
	"schedule_params": {
		"interval": "months",
		"frequency": 12,
		"days_of_week": null,
		"weeks_of_month": null,
		"last_day_of_month": null,
		"day_of_month": 10
	},
	"action_kwargs": {
		"job_guid": null
	}
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the RouteLocatorBuilder route and its modifyResponseBody filter, then compare the configured write-dates-as-timestamp behavior with the response produced by the RewriteFunction. Reproduce the sample using OffsetDateTime fields and verify that the completed response preserves the intended date representation rather than timestamps.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.