Skip to content

Commit

Permalink
Fix problem with deserialisation of numeric value types (due to int/l…
Browse files Browse the repository at this point in the history
…ong coercion by Jackson
  • Loading branch information
daviddenton committed Apr 29, 2024
1 parent 73e10cc commit 114d40a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
This list is not intended to be all-encompassing - it will document major and breaking API changes with their rationale
when appropriate:

### v2.18.0.1
- **data4k** [Fix] Problem with deserialisation of numeric value types (due to int/long coercion by Jackson

### v2.18.0.0
- **data4k** Make DataContainer contents mutable as chaining does not work otherwise.
- **data4k** Added updateWith() method to DataContainer to allow making a update of objects with an updated field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ abstract class DataContainer<DATA>(

private fun <IN : Any, OUT : Value<IN>> ValueFactory<OUT, IN>.parse(): (IN) -> OUT = {
when (it) {
is String -> parse(it)
is String, is Boolean, is Number -> parse(it.toString())
else -> of(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import dev.forkhandles.values.LongValue
import dev.forkhandles.values.LongValueFactory
import dev.forkhandles.values.StringValue
import dev.forkhandles.values.StringValueFactory
import dev.forkhandles.values.minValue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import strikt.api.expectThat
Expand Down Expand Up @@ -77,7 +78,7 @@ interface MainClassFields<C : ChildFields<G>, G : GrandchildFields, CONTENT> {
}

class LongType private constructor(value: Long) : LongValue(value) {
companion object : LongValueFactory<LongType>(::LongType)
companion object : LongValueFactory<LongType>(::LongType, 0L.minValue)
}

class BooleanType private constructor(value: Boolean) : BooleanValue(value) {
Expand Down
6 changes: 4 additions & 2 deletions values4k/src/main/kotlin/dev/forkhandles/values/factories.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.forkhandles.values
import java.io.File
import java.math.BigDecimal
import java.math.BigInteger
import java.net.URI
import java.net.URL
import java.time.Duration
import java.time.Instant
Expand All @@ -24,8 +25,8 @@ import java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME
import java.time.format.DateTimeFormatter.ISO_OFFSET_TIME
import java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME
import java.time.format.DateTimeFormatter.ofPattern
import java.util.UUID
import java.util.Base64
import java.util.UUID


private val rfcBase64Alphabet get() = "^[0-9A-Za-z+/=]+$".toRegex() // https://www.rfc-editor.org/rfc/rfc4648.html#section-4
Expand Down Expand Up @@ -129,7 +130,7 @@ open class UUIDValueFactory<DOMAIN : Value<UUID>>(

open class URLValueFactory<DOMAIN : Value<URL>>(
fn: (URL) -> DOMAIN, validation: Validation<URL>? = null
) : ValueFactory<DOMAIN, URL>(fn, validation, ::URL)
) : ValueFactory<DOMAIN, URL>(fn, validation, { URI.create(it).toURL() })

open class DurationValueFactory<DOMAIN : Value<Duration>>(
fn: (Duration) -> DOMAIN, validation: Validation<Duration>? = null
Expand Down Expand Up @@ -195,3 +196,4 @@ open class ZonedDateTimeValueFactory<DOMAIN : Value<ZonedDateTime>>(
open class FileValueFactory<DOMAIN : Value<File>>(
fn: (File) -> DOMAIN, validation: Validation<File>? = null
) : ValueFactory<DOMAIN, File>(fn, validation, { File(it) })

6 changes: 1 addition & 5 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugin.com.github.kt3k.coveralls=2.12.2

plugin.de.fayard.buildSrcLibs=0.60.5

plugin.io.github.gradle-nexus.publish-plugin=1.3.0
plugin.io.github.gradle-nexus.publish-plugin=2.0.0

plugin.io.codearte.nexus-staging=0.30.0

Expand All @@ -35,10 +35,6 @@ version.kotest=5.6.2
## # available=5.8.0
## # available=5.8.1

version.org.openjdk.jmh..jmh-generator-bytecode=1.36

version.org.openjdk.jmh..jmh-core=1.36

version.kotlin=1.9.23

version.kotlinx.coroutines=1.8.0
Expand Down

0 comments on commit 114d40a

Please sign in to comment.