This is because byte values are often sent as unsigned (but Java does not have matching concepts). So upper limit is 255, instead of 127. Changed was to for better interoperability with other systems, although discussion under [JACKSON-804] is unfortunately no longer available -- this referred to old Codehaus issue tracker, for Jackson 1.x.
-+ Tatu +- On Tue, May 5, 2020 at 4:10 PM Vladislav Bochenin <[email protected]> wrote: > > I'm receiving invalid value for `Byte` field during deserialization. > > Json: > > {"byteField" : 128 } > > Java: > > class Dto { > private Byte byteField; > ... getter/setter > } > > After deserialization I'm receiving `Dto.byteField` = -128 > > I found next code in Jackon-core library v.2.11.0 in > `com.fasterxml.jackson.core.JsonParser#getByteValue` > > public byte getByteValue() throws IOException { > int value = getIntValue(); > // So far so good: but does it fit? > // [JACKSON-804]: Let's actually allow range of [-128, 255], as those > are uniquely mapped > // (instead of just signed range of [-128, 127]) > if (value < MIN_BYTE_I || value > MAX_BYTE_I) { > throw new InputCoercionException(this, > String.format("Numeric value (%s) out of range of Java > byte", getText()), > JsonToken.VALUE_NUMBER_INT, Byte.TYPE); > } > return (byte) value; > } > > > but not able to find issue JACKSON-804 as well as any discussion about byte > range. > > Question: > > - Why Jackson allows to byte be more than 127? > > -- > You received this message because you are subscribed to the Google Groups > "jackson-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jackson-user/3f4b00d6-8c96-488e-8958-9fd1b18b57a7%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10gxjLv22tqG3xScuef3voJfx9QLoYdii7OP8QFW%2BHkuwQ%40mail.gmail.com.
