All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmJdk8Main.codecs.extended.DayOfWeekJsonCodec.kt Maven / Gradle / Ivy

package io.fluidsonic.json

import java.time.*


public object DayOfWeekJsonCodec : AbstractJsonCodec() {

	override fun JsonDecoder.decode(valueType: JsonCodingType): DayOfWeek =
		readString().let { raw ->
			when (raw) {
				"monday" -> DayOfWeek.MONDAY
				"tuesday" -> DayOfWeek.TUESDAY
				"wednesday" -> DayOfWeek.WEDNESDAY
				"thursday" -> DayOfWeek.THURSDAY
				"friday" -> DayOfWeek.FRIDAY
				"saturday" -> DayOfWeek.SATURDAY
				"sunday" -> DayOfWeek.SUNDAY
				else -> invalidValueError("weekday name of 'monday' through 'sunday' expected, got '$raw'")
			}
		}


	override fun JsonEncoder.encode(value: DayOfWeek): Unit =
		writeString(when (value) {
			DayOfWeek.MONDAY -> "monday"
			DayOfWeek.TUESDAY -> "tuesday"
			DayOfWeek.WEDNESDAY -> "wednesday"
			DayOfWeek.THURSDAY -> "thursday"
			DayOfWeek.FRIDAY -> "friday"
			DayOfWeek.SATURDAY -> "saturday"
			DayOfWeek.SUNDAY -> "sunday"
		})
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy