zonedDateTime 직렬화 이슈(spring boot 1.x 버전)

Seungyeon Choi·2021년 6월 7일
0

삽질기

목록 보기
1/2

배경

  • 업무 도메인 상 "시간"이란 개념을 다양하게 풀어내고 있음
  • spring boot 1.5.12 버전, jackson-datatype-jsr310 의존성이 추가된 상태
    • 미리 말하자면, 2.x 버전에서는 아래 문제 상관없음

문제 상황

  • api 서버를 만드는데, 클라이언트쪽으로 zonedDateTime 타입의 value가 굉장히 복잡하게 넘어옴. (뷰 뿌려줄 필요없으니 json 데이터만 넘겨줌)

    • 예를들어 서버에선 이런 친구가.....
    • 이렇게 직렬화가 되어 클라이언트로 넘어옴...,,
      {"offset":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"zone":{"id":"Asia/Seoul","rules":{"transitions":[{"offsetBefore":{"totalSeconds":30472,"id":"+08:27:52","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1908,"month":"APRIL","nano":0,"dayOfMonth":1,"dayOfWeek":"WEDNESDAY","dayOfYear":92,"hour":0,"minute":2,"second":8,"monthValue":4,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":128,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1908,"month":"APRIL","nano":0,"dayOfMonth":1,"dayOfWeek":"WEDNESDAY","dayOfYear":92,"hour":0,"minute":0,"second":0,"monthValue":4,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-1948782472},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1912,"month":"JANUARY","nano":0,"dayOfMonth":1,"dayOfWeek":"MONDAY","dayOfYear":1,"hour":0,"minute":30,"second":0,"monthValue":1,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":1800,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1912,"month":"JANUARY","nano":0,"dayOfMonth":1,"dayOfWeek":"MONDAY","dayOfYear":1,"hour":0,"minute":0,"second":0,"monthValue":1,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-1830414600},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1948,"month":"JUNE","nano":0,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":153,"hour":1,"minute":0,"second":0,"monthValue":6,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1948,"month":"JUNE","nano":0,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":153,"hour":0,"minute":0,"second":0,"monthValue":6,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-681210000},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1948,"month":"SEPTEMBER","nano":0,"dayOfMonth":12,"dayOfWeek":"SUNDAY","dayOfYear":256,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1948,"month":"SEPTEMBER","nano":0,"dayOfMonth":13,"dayOfWeek":"MONDAY","dayOfYear":257,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-672228000},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1949,"month":"APRIL","nano":0,"dayOfMonth":3,"dayOfWeek":"SUNDAY","dayOfYear":93,"hour":1,"minute":0,"second":0,"monthValue":4,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1949,"month":"APRIL","nano":0,"dayOfMonth":3,"dayOfWeek":"SUNDAY","dayOfYear":93,"hour":0,"minute":0,"second":0,"monthValue":4,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-654771600},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1949,"month":"SEPTEMBER","nano":0,"dayOfMonth":10,"dayOfWeek":"SATURDAY","dayOfYear":253,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1949,"month":"SEPTEMBER","nano":0,"dayOfMonth":11,"dayOfWeek":"SUNDAY","dayOfYear":254,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-640864800},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1950,"month":"APRIL","nano":0,"dayOfMonth":1,"dayOfWeek":"SATURDAY","dayOfYear":91,"hour":1,"minute":0,"second":0,"monthValue":4,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1950,"month":"APRIL","nano":0,"dayOfMonth":1,"dayOfWeek":"SATURDAY","dayOfYear":91,"hour":0,"minute":0,"second":0,"monthValue":4,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-623408400},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1950,"month":"SEPTEMBER","nano":0,"dayOfMonth":9,"dayOfWeek":"SATURDAY","dayOfYear":252,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1950,"month":"SEPTEMBER","nano":0,"dayOfMonth":10,"dayOfWeek":"SUNDAY","dayOfYear":253,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-609415200},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1951,"month":"MAY","nano":0,"dayOfMonth":6,"dayOfWeek":"SUNDAY","dayOfYear":126,"hour":1,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1951,"month":"MAY","nano":0,"dayOfMonth":6,"dayOfWeek":"SUNDAY","dayOfYear":126,"hour":0,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-588848400},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1951,"month":"SEPTEMBER","nano":0,"dayOfMonth":8,"dayOfWeek":"SATURDAY","dayOfYear":251,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1951,"month":"SEPTEMBER","nano":0,"dayOfMonth":9,"dayOfWeek":"SUNDAY","dayOfYear":252,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-577965600},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1954,"month":"MARCH","nano":0,"dayOfMonth":20,"dayOfWeek":"SATURDAY","dayOfYear":79,"hour":23,"minute":30,"second":0,"monthValue":3,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-1800,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1954,"month":"MARCH","nano":0,"dayOfMonth":21,"dayOfWeek":"SUNDAY","dayOfYear":80,"hour":0,"minute":0,"second":0,"monthValue":3,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-498128400},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1955,"month":"MAY","nano":0,"dayOfMonth":5,"dayOfWeek":"THURSDAY","dayOfYear":125,"hour":1,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1955,"month":"MAY","nano":0,"dayOfMonth":5,"dayOfWeek":"THURSDAY","dayOfYear":125,"hour":0,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-462702600},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1955,"month":"SEPTEMBER","nano":0,"dayOfMonth":8,"dayOfWeek":"THURSDAY","dayOfYear":251,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1955,"month":"SEPTEMBER","nano":0,"dayOfMonth":9,"dayOfWeek":"FRIDAY","dayOfYear":252,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-451733400},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1956,"month":"MAY","nano":0,"dayOfMonth":20,"dayOfWeek":"SUNDAY","dayOfYear":141,"hour":1,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1956,"month":"MAY","nano":0,"dayOfMonth":20,"dayOfWeek":"SUNDAY","dayOfYear":141,"hour":0,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-429784200},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1956,"month":"SEPTEMBER","nano":0,"dayOfMonth":29,"dayOfWeek":"SATURDAY","dayOfYear":273,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1956,"month":"SEPTEMBER","nano":0,"dayOfMonth":30,"dayOfWeek":"SUNDAY","dayOfYear":274,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-418296600},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1957,"month":"MAY","nano":0,"dayOfMonth":5,"dayOfWeek":"SUNDAY","dayOfYear":125,"hour":1,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1957,"month":"MAY","nano":0,"dayOfMonth":5,"dayOfWeek":"SUNDAY","dayOfYear":125,"hour":0,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-399544200},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1957,"month":"SEPTEMBER","nano":0,"dayOfMonth":21,"dayOfWeek":"SATURDAY","dayOfYear":264,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1957,"month":"SEPTEMBER","nano":0,"dayOfMonth":22,"dayOfWeek":"SUNDAY","dayOfYear":265,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-387451800},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1958,"month":"MAY","nano":0,"dayOfMonth":4,"dayOfWeek":"SUNDAY","dayOfYear":124,"hour":1,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1958,"month":"MAY","nano":0,"dayOfMonth":4,"dayOfWeek":"SUNDAY","dayOfYear":124,"hour":0,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-368094600},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1958,"month":"SEPTEMBER","nano":0,"dayOfMonth":20,"dayOfWeek":"SATURDAY","dayOfYear":263,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1958,"month":"SEPTEMBER","nano":0,"dayOfMonth":21,"dayOfWeek":"SUNDAY","dayOfYear":264,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-356002200},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1959,"month":"MAY","nano":0,"dayOfMonth":3,"dayOfWeek":"SUNDAY","dayOfYear":123,"hour":1,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1959,"month":"MAY","nano":0,"dayOfMonth":3,"dayOfWeek":"SUNDAY","dayOfYear":123,"hour":0,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-336645000},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1959,"month":"SEPTEMBER","nano":0,"dayOfMonth":19,"dayOfWeek":"SATURDAY","dayOfYear":262,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1959,"month":"SEPTEMBER","nano":0,"dayOfMonth":20,"dayOfWeek":"SUNDAY","dayOfYear":263,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-324552600},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1960,"month":"MAY","nano":0,"dayOfMonth":1,"dayOfWeek":"SUNDAY","dayOfYear":122,"hour":1,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1960,"month":"MAY","nano":0,"dayOfMonth":1,"dayOfWeek":"SUNDAY","dayOfYear":122,"hour":0,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-305195400},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":34200,"id":"+09:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1960,"month":"SEPTEMBER","nano":0,"dayOfMonth":17,"dayOfWeek":"SATURDAY","dayOfYear":261,"hour":23,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1960,"month":"SEPTEMBER","nano":0,"dayOfMonth":18,"dayOfWeek":"SUNDAY","dayOfYear":262,"hour":0,"minute":0,"second":0,"monthValue":9,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-293103000},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":30600,"id":"+08:30","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1961,"month":"AUGUST","nano":0,"dayOfMonth":10,"dayOfWeek":"THURSDAY","dayOfYear":222,"hour":0,"minute":30,"second":0,"monthValue":8,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":1800,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1961,"month":"AUGUST","nano":0,"dayOfMonth":10,"dayOfWeek":"THURSDAY","dayOfYear":222,"hour":0,"minute":0,"second":0,"monthValue":8,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":-264933000},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1987,"month":"MAY","nano":0,"dayOfMonth":10,"dayOfWeek":"SUNDAY","dayOfYear":130,"hour":3,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1987,"month":"MAY","nano":0,"dayOfMonth":10,"dayOfWeek":"SUNDAY","dayOfYear":130,"hour":2,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":547578000},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1987,"month":"OCTOBER","nano":0,"dayOfMonth":11,"dayOfWeek":"SUNDAY","dayOfYear":284,"hour":2,"minute":0,"second":0,"monthValue":10,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1987,"month":"OCTOBER","nano":0,"dayOfMonth":11,"dayOfWeek":"SUNDAY","dayOfYear":284,"hour":3,"minute":0,"second":0,"monthValue":10,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":560883600},"gap":false,"overlap":true},{"offsetBefore":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1988,"month":"MAY","nano":0,"dayOfMonth":8,"dayOfWeek":"SUNDAY","dayOfYear":129,"hour":3,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":3600,"negative":false,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1988,"month":"MAY","nano":0,"dayOfMonth":8,"dayOfWeek":"SUNDAY","dayOfYear":129,"hour":2,"minute":0,"second":0,"monthValue":5,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":579027600},"gap":true,"overlap":false},{"offsetBefore":{"totalSeconds":36000,"id":"+10:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"offsetAfter":{"totalSeconds":32400,"id":"+09:00","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"dateTimeAfter":{"year":1988,"month":"OCTOBER","n~~텍스트~~ano":0,"dayOfMonth":9,"dayOfWeek":"SUNDAY","dayOfYear":283,"hour":2,"minute":0,"second":0,"monthValue":10,"chronology":{"id":"ISO","calendarType":"iso8601"}},"duration":{"seconds":-3600,"negative":true,"units":["SECONDS","NANOS"],"nano":0,"zero":false},"dateTimeBefore":{"year":1988,"month":"OCTOBER","nano":0,"dayOfMonth":9,"dayOfWeek":"SUNDAY","dayOfYear":283,"hour":3,"minute":0,"second":0,"monthValue":10,"chronology":{"id":"ISO","calendarType":"iso8601"}},"instant":{"nano":0,"epochSecond":592333200},"gap":false,"overlap":true}],"transitionRules":[],"fixedOffset":false}},"year":2021,"month":"JUNE","nano":148000000,"dayOfMonth":7,"dayOfWeek":"MONDAY","dayOfYear":158,"hour":23,"minute":43,"second":25,"monthValue":6,"chronology":{"id":"ISO","calendarType":"iso8601"}}
  • AS-IS
    위 이미지

  • TO-BE
    yyyy-MM-dd'T'HH:mm:ss'${timezone}' format 으로 출력 //UTC 로 출력할 예정이라 postfix가 Z지만 중요하지 않으므로 pass

    "2021-06-08T00:51:48.281+09:00"

해결법

ZonedDateTime 값이 ResponseEntity 에 담길 때 default로 설정된 직렬화 과정을 빼줌

방법1) @Configuration 파일 추가

@Configuration
public class JacksonConfig {

    @Bean
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
    	// 객체 converting 과정에 대해선 여기서 처리하면 됨
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        return objectMapper;
    }
}

방법2) application.properties/yml 에 설정 코드 추가

// properties
spring.jackson.serialization.write_dates_as_timestamps=false

// yml
spring.jackson.serialization.write-dates-as-timestamps: false

[번외] 왜 버전 2.x 에선 이런 문제가 없을까?
상위버전에서는 위 설정이 default로 false 처리 되어있음. 그래서 문제가 없다..
(더 자세한 내용은 여기 참고)

어떻게 해결법에 도달했나?

1. 구글링

키워드: "@restcontroller zoneddatetime response"

키워드 산출 근거
1. @restcontroller: 최종적으로 데이터를 반환하는 과정은 이 어노테이션과 연관있음
2. zoneddatetime: 이 타입의 객체가 제대로 전달이 안되고 있음....
3. response: 그냥...."응답결과"에 문제가 있는 것이니 그걸 나타내는 키워드.... 원하는 해결법을 담은 글에 한번쯤은 쓰일 것 같아서 넣었음...

스터디때 묻고싶은것: 여러분만의 구글링 팁이 있나요...?

이렇게 검색해서 여~러~가~지 링크가 나왔는데 아래 두개를 유심히 읽었다

친절한 링크
갓jojoldu님 링크

구글링을 통해 내린 결론

  • 데이터 직렬화? converting? 과정에서의 문제가 있다
  • 아 그럼 @restcontroller에서 http body에 담을 데이터converting을 어떻게 해주지?

2. @Restcontroller 가 어떻게 객체 데이터를 converting 하는가?



이미지 출처: https://wondongho.tistory.com/76

@RestController가 Data를 반환하기 위해서는 viewResolver 대신에 HttpMessageConverter가 동작합니다. HttpMessageConverter에는 여러 Converter가 등록되어 있고, 반환해야 하는 데이터에 따라 사용되는 Converter가 달라집니다. 단순 문자열인 경우에는 StringHttpMessageConverter가 사용되고, 객체인 경우에는 MappingJackson2HttpMessageConverter가 사용되며, 데이터 종류에 따라 서로 다른 MessageConverter가 작동하게 됩니다. Spring은 클라이언트의 HTTP Accept 헤더와 서버의 컨트롤러 반환 타입 정보 둘을 조합해 적합한 HttpMessageConverter를 선택하여 이를 처리합니다.

글 출처: https://mangkyu.tistory.com/49


이 과정을 통해 내린 결론

  • 아 ... MappingJackson2HttpMessageConverter가 default로 시간값들 converting 해주는 설정이 있겠군 => 근데 찾아보니까 converter에 붙는 object mapper 에 속한 설정에 문제가 있었음

3. converter 에 들어가는 object mapper custom 하기

3.1 POJO <-> json 변환 과정

  1. MappingJackson2HttpMessageConverter 클래스가 Spring Boot 초기 구동시 JacksonHttpMessageConvertersConfiguration 클래스에 의해 싱글턴 빈으로 등록되어 POJO-JSON간의 상호 변환을 수행한다.

  2. MappingJackson2HttpMessageConverter는 이름에서 보여지듯이 Java 진영에서 널리 쓰이는 JSON 라이브러리인 Jackson(Spring Boot 1.3.5 기준 Jackson 2.6 내장)을 사용하여 메시지를 상호 변환한다.

  3. MappingJackson2HttpMessageConverterHttpMessageConverter 인터페이스의 구현체로 read(), write() 메써드를 이용하여 JSON을 처리한다. 내부적으로는 Jackson이 제공하는 ObjectMapper 클래스를 사용하는데 커스텀 설정을 적용하여 미리 빈으로 등록해두면 변환시 자동으로 해당 빈을 대신 사용한다.

출처: https://jsonobject.tistory.com/235

3.2 ObjectMapper 설정 custom 하기

== 해결법 == 이번 해결을 위한 흐름의 결론

profile
캘린더 만드는 개발자입니당

0개의 댓글