-
Notifications
You must be signed in to change notification settings - Fork 99
Value i128 serializer breaks cbor <=> json Value to Value conversions #140
Comments
Hello, that is unfortuate. Can you post a complete example with code of a failed conversion? |
use serde::{Serialize, Deserialize};
use serde_cbor::value::Value as CborValue;
#[derive(Deserialize, Serialize)]
struct Foo { x: i32 }
fn main() {
let foo = Foo { x: -13 };
let cbor_bytes = serde_cbor::ser::to_vec(&foo)
.expect("failed to serialize to cbor bytes");
let cbor_val: CborValue = serde_cbor::from_slice(&*cbor_bytes)
.expect("failed to deserialize to cbor Value");
println!("{:?}", cbor_val);
let json_val = serde_json::to_value(cbor_val)
.expect("failed conversion");
println!("{:?}", json_val);
} This obviously happens whenever integer values of any type (not just |
Thanks for the example code. Would you mind opening an issue for serde-rs/json and ask them to accept |
Would it help if serde-cbor Values emit an u64 for positive numbers and i64 for negative number whenever possible? |
Probably yes. |
@rslife would you like to submit a PR? |
I will send a PR from my home account later. |
UnsignedInteger(u64): for all non-negative values SignedInteger(i64): for negative values that fit in a i64. LargeSignedInteger(i128): for negative values that can't be represented by i64. This should fix pyfisch#140. Signed-off-by: Mohammad AlSaleh <[email protected]>
UnsignedInteger(u64): for all non-negative values SignedInteger(i64): for negative values that fit in a i64. LargeSignedInteger(i128): for negative values that can't be represented by i64. This should fix pyfisch#140. Signed-off-by: Mohammad AlSaleh <[email protected]>
Hello.
Starting with 8cfcea9, direct conversions between cbor
Value
s and jsonValue
s is no longer possible.I fully understand the rationale behind using one integer type to cover the full integer value range supported by cbor. But I wonder what are your thoughts on bringing back, what was admittedly accidental, support for this type of conversion.
The text was updated successfully, but these errors were encountered: