Joda Time Adapters for kjson
Prior to the release of Java 1.8, the Joda Time library provided data and time
implementations superior to those available in the standard JDK.
It has now become redundant, following the release of the java.time.xxx
classes in JDK 1.8, but many applications
still use the Joda Time libraries, and it is likely to be some time before all those older applications are converted or
replaced.
The kjson-joda-time
library provides custom serialization and deserialization classes to allow the use of the
kjson
library with applications that still use the Joda Time classes.
To use this library, add the conversions required to a JSONConfig
within your application, as shown below:
val config = JSONConfig {
addJodaInstantFromJSON() // to deserialize org.joda.time.Instant
addJodaInstantToJSON() // to serialize org.joda.time.Instant
addJodaLocalTimeFromJSON() // to deserialize org.joda.time.LocalTime
addJodaLocalTimeToJSON() // to serialize org.joda.time.LocalTime
addJodaLocalDateFromJSON() // to deserialize org.joda.time.LocalDate
addJodaLocalDateToJSON() // to serialize org.joda.time.LocalDate
addJodaLocalDateTimeFromJSON() // to deserialize org.joda.time.LocalDateTime
addJodaLocalDateTimeToJSON() // to serialize org.joda.time.LocalDateTime
addJodaDateTimeFromJSON() // to deserialize org.joda.time.DateTime
addJodaDateTimeToJSON() // to serialize org.joda.time.DateTime
addJodaYearMonthFromJSON() // to deserialize org.joda.time.YearMonth
addJodaYearMonthToJSON() // to serialize org.joda.time.YearMonth
addJodaMonthDayFromJSON() // to deserialize org.joda.time.MonthDay
addJodaMonthDayToJSON() // to serialize org.joda.time.MonthDay
}
Alternatively, to include the entire set of conversions:
val config = JSONConfig {
combineAll(JodaTimeJSON.config)
}
This is the initial release of the library; further classes and more documentation will be added later.
The latest version of the library is 0.4, and it may be obtained from the Maven Central repository.
<dependency>
<groupId>io.kjson</groupId>
<artifactId>kjson-joda-time</artifactId>
<version>0.4</version>
</dependency>
implementation 'io.kjson:kjson-joda-time:0.4'
implementation("io.kjson:kjson-joda-time:0.4")
Peter Wall
2023-10-15