Jackson
cosid-jackson (package me.ahoo.cosid.jackson) brings @AsString for Jackson 3 (tools.jackson): a long id is written as text and read back from it, for JavaScript clients that cannot hold 63-bit numbers.
java
@AsString long id; // radix 62, 11 digits, padded (as in 4.x)
@AsString(generator = "order") long orderId; // the codec of generator "order"
@AsString(codec = Codec.TO_STRING) long a; // decimal text
@AsString(radix = 36, width = 13, padStart = false) long b;
@AsString(codec = Codec.FRIENDLY, layout = Preset.SNOWFLAKE_S, zone = "Asia/Shanghai") long c;
@AsString(codec = Codec.FRIENDLY, timeBits = 41, nodeBits = 5, seqBits = 17, epoch = 1700000000000L) long d;generator = …and the inline attributes are exclusive.- The inline codecs need no module.
generator = …needsnew CosIdJacksonModule(runtime)on theJsonMapper; Spring Boot registers aCosIdJacksonModulebean. - Reading accepts the text, a JSON number the codec could have written, and an empty string as
null. - Jackson 3 only: Jackson 2 (
com.fasterxml.jackson.databind) is not supported.
From 4.x
The attributes of @AsString were renamed:
| 4.x | 5.0 |
|---|---|
value (AsString.Type) | codec (AsString.Codec) |
Type.TO_STRING, Type.RADIX | Codec.TO_STRING, Codec.RADIX |
Type.FRIENDLY_ID | Codec.FRIENDLY |
radixCharSize | width (0, the default, for as many digits as a long takes in the radix) |
radixPadStart | padStart |
timestampBit, machineBit, sequenceBit | timeBits, nodeBits, seqBits (all three or none) |
epoch | epoch (unset: the epoch of layout) |
| — | generator, radix (62 by default), layout, zone |
The friendly text changed its default: 4.x FRIENDLY_ID did not pad the node and the sequence (…-1-5), 5.0 Codec.FRIENDLY pads them (…-0001-0005). To keep the 4.x text, write padStart = false. Both forms decode.
