-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: 날짜를 커스텀 Serializer를 이용해 직렬화 및 역직렬화 하도록 변경 (#881)
Related to: 880
- Loading branch information
Showing
16 changed files
with
104 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...oid/2023-emmsale/app/src/main/java/com/emmsale/data/apiModel/serializer/DateSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.emmsale.data.apiModel.serializer | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializer | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Serializer(forClass = LocalDate::class) | ||
class DateSerializer : KSerializer<LocalDate> { | ||
|
||
private val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||
|
||
override fun serialize(encoder: Encoder, value: LocalDate) { | ||
encoder.encodeString(value.format(dateFormatter)) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): LocalDate = | ||
LocalDate.parse(decoder.decodeString(), dateFormatter) | ||
} |
22 changes: 22 additions & 0 deletions
22
...2023-emmsale/app/src/main/java/com/emmsale/data/apiModel/serializer/DateTimeSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.emmsale.data.apiModel.serializer | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializer | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Serializer(forClass = LocalDateTime::class) | ||
object DateTimeSerializer : KSerializer<LocalDateTime> { | ||
private val formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd:HH:mm:ss") | ||
|
||
override fun serialize(encoder: Encoder, value: LocalDateTime) { | ||
encoder.encodeString(value.format(formatter)) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): LocalDateTime = | ||
LocalDateTime.parse(decoder.decodeString(), formatter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.