|
1 | 1 | package com.fasterxml.jackson.module.kotlin.deser.deserializers
|
2 | 2 |
|
3 |
| -import com.fasterxml.jackson.core.JsonToken |
4 |
| -import com.fasterxml.jackson.core.exc.InputCoercionException |
5 | 3 | import com.fasterxml.jackson.databind.*
|
6 | 4 | import com.fasterxml.jackson.databind.deser.std.StdKeyDeserializer
|
7 | 5 | import com.fasterxml.jackson.databind.deser.std.StdKeyDeserializers
|
8 |
| -import com.fasterxml.jackson.module.kotlin.asUByte |
9 |
| -import com.fasterxml.jackson.module.kotlin.asUInt |
10 |
| -import com.fasterxml.jackson.module.kotlin.asULong |
11 |
| -import com.fasterxml.jackson.module.kotlin.asUShort |
| 6 | +import java.math.BigInteger |
12 | 7 |
|
13 | 8 | // The reason why key is treated as nullable is to match the tentative behavior of StdKeyDeserializer.
|
14 | 9 | // If StdKeyDeserializer is modified, need to modify this too.
|
15 | 10 |
|
16 | 11 | internal object UByteKeyDeserializer : StdKeyDeserializer(TYPE_SHORT, UByte::class.java) {
|
17 |
| - override fun deserializeKey(key: String?, ctxt: DeserializationContext): UByte? = super.deserializeKey(key, ctxt) |
18 |
| - ?.let { |
19 |
| - (it as Short).asUByte() ?: throw InputCoercionException( |
20 |
| - null, |
21 |
| - "Numeric value (${key}) out of range of UByte (0 - ${UByte.MAX_VALUE}).", |
22 |
| - JsonToken.VALUE_NUMBER_INT, |
23 |
| - UByte::class.java |
24 |
| - ) |
25 |
| - } |
| 12 | + override fun deserializeKey(key: String?, ctxt: DeserializationContext): UByte? = |
| 13 | + key?.let { UByteChecker.readWithRangeCheck(null, _parseInt(it)) } |
26 | 14 | }
|
27 | 15 |
|
28 | 16 | internal object UShortKeyDeserializer : StdKeyDeserializer(TYPE_INT, UShort::class.java) {
|
29 |
| - override fun deserializeKey(key: String?, ctxt: DeserializationContext): UShort? = super.deserializeKey(key, ctxt) |
30 |
| - ?.let { |
31 |
| - (it as Int).asUShort() ?: throw InputCoercionException( |
32 |
| - null, |
33 |
| - "Numeric value (${key}) out of range of UShort (0 - ${UShort.MAX_VALUE}).", |
34 |
| - JsonToken.VALUE_NUMBER_INT, |
35 |
| - UShort::class.java |
36 |
| - ) |
37 |
| - } |
| 17 | + override fun deserializeKey(key: String?, ctxt: DeserializationContext): UShort? = |
| 18 | + key?.let { UShortChecker.readWithRangeCheck(null, _parseInt(it)) } |
38 | 19 | }
|
39 | 20 |
|
40 | 21 | internal object UIntKeyDeserializer : StdKeyDeserializer(TYPE_LONG, UInt::class.java) {
|
41 |
| - override fun deserializeKey(key: String?, ctxt: DeserializationContext): UInt? = super.deserializeKey(key, ctxt) |
42 |
| - ?.let { |
43 |
| - (it as Long).asUInt() ?: throw InputCoercionException( |
44 |
| - null, |
45 |
| - "Numeric value (${key}) out of range of UInt (0 - ${UInt.MAX_VALUE}).", |
46 |
| - JsonToken.VALUE_NUMBER_INT, |
47 |
| - UInt::class.java |
48 |
| - ) |
49 |
| - } |
| 22 | + override fun deserializeKey(key: String?, ctxt: DeserializationContext): UInt? = |
| 23 | + key?.let { UIntChecker.readWithRangeCheck(null, _parseLong(it)) } |
50 | 24 | }
|
51 | 25 |
|
52 |
| -// kind parameter is dummy. |
53 |
| -internal object ULongKeyDeserializer : StdKeyDeserializer(TYPE_LONG, ULong::class.java) { |
54 |
| - override fun deserializeKey(key: String?, ctxt: DeserializationContext): ULong? = key?.let { |
55 |
| - it.toBigInteger().asULong() ?: throw InputCoercionException( |
56 |
| - null, |
57 |
| - "Numeric value (${key}) out of range of ULong (0 - ${ULong.MAX_VALUE}).", |
58 |
| - JsonToken.VALUE_NUMBER_INT, |
59 |
| - ULong::class.java |
60 |
| - ) |
61 |
| - } |
| 26 | +internal object ULongKeyDeserializer : StdKeyDeserializer(-1, ULong::class.java) { |
| 27 | + override fun deserializeKey(key: String?, ctxt: DeserializationContext): ULong? = |
| 28 | + key?.let { ULongChecker.readWithRangeCheck(null, BigInteger(it)) } |
62 | 29 | }
|
63 | 30 |
|
64 | 31 | internal object KotlinKeyDeserializers : StdKeyDeserializers() {
|
|
0 commit comments