Дата ответа отдыха в развернутом виде.Не строка - PullRequest
0 голосов
/ 05 июня 2018

Я обновил версию com.faster.jackson до 2.8.10.После этого Дата наступает следующим образом.

    "offset": {
        "totalSeconds": 19800,
        "id": "+05:30",
        "rules": {
            "fixedOffset": true,
            "transitions": [],
            "transitionRules": []
        }
    },
    "zone": {
        "id": "Asia/Kolkata",
        "rules": {
            "fixedOffset": false,
            "transitions": [
                {
                    "offsetBefore": {
                        "totalSeconds": 21208,
                        "id": "+05:53:28",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "offsetAfter": {
                        "totalSeconds": 21200,
                        "id": "+05:53:20",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "duration": {
                        "seconds": -8,
                        "units": [
                            "SECONDS",
                            "NANOS"
                        ],
                        "zero": false,
                        "negative": true,
                        "nano": 0
                    },
                    "gap": false,
                    "overlap": true,
                    "dateTimeAfter": {
                        "monthValue": 6,
                        "year": 1854,
                        "month": "JUNE",
                        "dayOfMonth": 27,
                        "dayOfWeek": "TUESDAY",
                        "dayOfYear": 178,
                        "hour": 23,
                        "minute": 59,
                        "second": 52,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "dateTimeBefore": {
                        "monthValue": 6,
                        "year": 1854,
                        "month": "JUNE",
                        "dayOfMonth": 28,
                        "dayOfWeek": "WEDNESDAY",
                        "dayOfYear": 179,
                        "hour": 0,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "instant": {
                        "nano": 0,
                        "epochSecond": -3645237208
                    }
                },
                {
                    "offsetBefore": {
                        "totalSeconds": 21200,
                        "id": "+05:53:20",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "offsetAfter": {
                        "totalSeconds": 19270,
                        "id": "+05:21:10",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "duration": {
                        "seconds": -1930,
                        "units": [
                            "SECONDS",
                            "NANOS"
                        ],
                        "zero": false,
                        "negative": true,
                        "nano": 0
                    },
                    "gap": false,
                    "overlap": true,
                    "dateTimeAfter": {
                        "monthValue": 12,
                        "year": 1869,
                        "month": "DECEMBER",
                        "dayOfMonth": 31,
                        "dayOfWeek": "FRIDAY",
                        "dayOfYear": 365,
                        "hour": 23,
                        "minute": 27,
                        "second": 50,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "dateTimeBefore": {
                        "monthValue": 1,
                        "year": 1870,
                        "month": "JANUARY",
                        "dayOfMonth": 1,
                        "dayOfWeek": "SATURDAY",
                        "dayOfYear": 1,
                        "hour": 0,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "instant": {
                        "nano": 0,
                        "epochSecond": -3155694800
                    }
                },
                {
                    "offsetBefore": {
                        "totalSeconds": 19270,
                        "id": "+05:21:10",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "offsetAfter": {
                        "totalSeconds": 19800,
                        "id": "+05:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "duration": {
                        "seconds": 530,
                        "units": [
                            "SECONDS",
                            "NANOS"
                        ],
                        "zero": false,
                        "negative": false,
                        "nano": 0
                    },
                    "gap": true,
                    "overlap": false,
                    "dateTimeAfter": {
                        "monthValue": 1,
                        "year": 1906,
                        "month": "JANUARY",
                        "dayOfMonth": 1,
                        "dayOfWeek": "MONDAY",
                        "dayOfYear": 1,
                        "hour": 0,
                        "minute": 8,
                        "second": 50,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "dateTimeBefore": {
                        "monthValue": 1,
                        "year": 1906,
                        "month": "JANUARY",
                        "dayOfMonth": 1,
                        "dayOfWeek": "MONDAY",
                        "dayOfYear": 1,
                        "hour": 0,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "instant": {
                        "nano": 0,
                        "epochSecond": -2019705670
                    }
                },
                {
                    "offsetBefore": {
                        "totalSeconds": 19800,
                        "id": "+05:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "offsetAfter": {
                        "totalSeconds": 23400,
                        "id": "+06:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "duration": {
                        "seconds": 3600,
                        "units": [
                            "SECONDS",
                            "NANOS"
                        ],
                        "zero": false,
                        "negative": false,
                        "nano": 0
                    },
                    "gap": true,
                    "overlap": false,
                    "dateTimeAfter": {
                        "monthValue": 10,
                        "year": 1941,
                        "month": "OCTOBER",
                        "dayOfMonth": 1,
                        "dayOfWeek": "WEDNESDAY",
                        "dayOfYear": 274,
                        "hour": 1,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "dateTimeBefore": {
                        "monthValue": 10,
                        "year": 1941,
                        "month": "OCTOBER",
                        "dayOfMonth": 1,
                        "dayOfWeek": "WEDNESDAY",
                        "dayOfYear": 274,
                        "hour": 0,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "instant": {
                        "nano": 0,
                        "epochSecond": -891581400
                    }
                },
                {
                    "offsetBefore": {
                        "totalSeconds": 23400,
                        "id": "+06:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "offsetAfter": {
                        "totalSeconds": 19800,
                        "id": "+05:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "duration": {
                        "seconds": -3600,
                        "units": [
                            "SECONDS",
                            "NANOS"
                        ],
                        "zero": false,
                        "negative": true,
                        "nano": 0
                    },
                    "gap": false,
                    "overlap": true,
                    "dateTimeAfter": {
                        "monthValue": 5,
                        "year": 1942,
                        "month": "MAY",
                        "dayOfMonth": 14,
                        "dayOfWeek": "THURSDAY",
                        "dayOfYear": 134,
                        "hour": 23,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "dateTimeBefore": {
                        "monthValue": 5,
                        "year": 1942,
                        "month": "MAY",
                        "dayOfMonth": 15,
                        "dayOfWeek": "FRIDAY",
                        "dayOfYear": 135,
                        "hour": 0,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "instant": {
                        "nano": 0,
                        "epochSecond": -872058600
                    }
                },
                {
                    "offsetBefore": {
                        "totalSeconds": 19800,
                        "id": "+05:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "offsetAfter": {
                        "totalSeconds": 23400,
                        "id": "+06:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "duration": {
                        "seconds": 3600,
                        "units": [
                            "SECONDS",
                            "NANOS"
                        ],
                        "zero": false,
                        "negative": false,
                        "nano": 0
                    },
                    "gap": true,
                    "overlap": false,
                    "dateTimeAfter": {
                        "monthValue": 9,
                        "year": 1942,
                        "month": "SEPTEMBER",
                        "dayOfMonth": 1,
                        "dayOfWeek": "TUESDAY",
                        "dayOfYear": 244,
                        "hour": 1,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "dateTimeBefore": {
                        "monthValue": 9,
                        "year": 1942,
                        "month": "SEPTEMBER",
                        "dayOfMonth": 1,
                        "dayOfWeek": "TUESDAY",
                        "dayOfYear": 244,
                        "hour": 0,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "instant": {
                        "nano": 0,
                        "epochSecond": -862637400
                    }
                },
                {
                    "offsetBefore": {
                        "totalSeconds": 23400,
                        "id": "+06:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "offsetAfter": {
                        "totalSeconds": 19800,
                        "id": "+05:30",
                        "rules": {
                            "fixedOffset": true,
                            "transitions": [],
                            "transitionRules": []
                        }
                    },
                    "duration": {
                        "seconds": -3600,
                        "units": [
                            "SECONDS",
                            "NANOS"
                        ],
                        "zero": false,
                        "negative": true,
                        "nano": 0
                    },
                    "gap": false,
                    "overlap": true,
                    "dateTimeAfter": {
                        "monthValue": 10,
                        "year": 1945,
                        "month": "OCTOBER",
                        "dayOfMonth": 14,
                        "dayOfWeek": "SUNDAY",
                        "dayOfYear": 287,
                        "hour": 23,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "dateTimeBefore": {
                        "monthValue": 10,
                        "year": 1945,
                        "month": "OCTOBER",
                        "dayOfMonth": 15,
                        "dayOfWeek": "MONDAY",
                        "dayOfYear": 288,
                        "hour": 0,
                        "minute": 0,
                        "second": 0,
                        "nano": 0,
                        "chronology": {
                            "calendarType": "iso8601",
                            "id": "ISO"
                        }
                    },
                    "instant": {
                        "nano": 0,
                        "epochSecond": -764145000
                    }
                }
            ],
            "transitionRules": []
        }
    },
    "monthValue": 6,
    "year": 2018,
    "month": "JUNE",
    "dayOfMonth": 5,
    "dayOfWeek": "TUESDAY",
    "dayOfYear": 156,
    "hour": 14,
    "minute": 10,
    "second": 21,
    "nano": 534000000,
    "chronology": {
        "calendarType": "iso8601",
        "id": "ISO"
    }
}

Ожидаемый формат: "createDate": "2018-06-05T08: 17: 14.010Z"

Я попытался добавить spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false.Все еще идет то же самое.

Класс модели

public class VoucherResponseDTO implements Serializable {

private ZonedDateTime createdDate;
//getters & setters

}

До выхода обновления версии Джексона было так: "2018-06-05T08: 17: 14.010Z"

У меня есть класс ниже.

 @Configuration
public class JacksonConfiguration {

    @Bean
    Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
        JavaTimeModule module = new JavaTimeModule();
        module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
        module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
        module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
        module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
        module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
        return new Jackson2ObjectMapperBuilder()
                .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                .findModulesViaServiceLoader(true)
                .modulesToInstall(module);
    }
}

Не могли бы вы помочь получить дату в виде строки

Спасибо и с уважением

1 Ответ

0 голосов
/ 06 июня 2018

В качестве обходного пути вы можете пометить соответствующее поле с помощью

class Bean {
     @JsonSerialize(using = JSR310DateTimeSerializer.class)
     public ZonedDateTime dateTime;
}

Конечно, это решение не масштабируется.Если вы используете много java.time компонентов в ваших классах моделей, вы не хотите аннотировать каждое поле определенным классом сериализатора.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...