Skip to content

Commit

Permalink
Merge pull request #77 from olexander-movchan/om/fix-schema-json-pars…
Browse files Browse the repository at this point in the history
…e-signed-int

Fix schema JSON deserialization of signed integers
  • Loading branch information
abizjak committed Mar 20, 2023
2 parents e746521 + 0b64d10 commit 6e1e2fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased changes

- Fix schema JSON deserialization of negative signed numbers.

## concordium-contracts-common 5.3.0 (2023-03-16)

- Add `Display` implementation for `OwnedParameter` and `Parameter`, which uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn write_bytes_from_json_schema_type<W: Write>(
}
Type::I8 => {
if let Value::Number(n) = json {
let n = n.as_u64().ok_or(JsonError::SignedIntRequired)?;
let n = n.as_i64().ok_or(JsonError::SignedIntRequired)?;
let n: i8 = n.try_into()?;
serial!(n, out)
} else {
Expand All @@ -123,7 +123,7 @@ fn write_bytes_from_json_schema_type<W: Write>(
}
Type::I16 => {
if let Value::Number(n) = json {
let n = n.as_u64().ok_or(JsonError::SignedIntRequired)?;
let n = n.as_i64().ok_or(JsonError::SignedIntRequired)?;
let n: i16 = n.try_into()?;
serial!(n, out)
} else {
Expand All @@ -132,7 +132,7 @@ fn write_bytes_from_json_schema_type<W: Write>(
}
Type::I32 => {
if let Value::Number(n) = json {
let n = n.as_u64().ok_or(JsonError::SignedIntRequired)?;
let n = n.as_i64().ok_or(JsonError::SignedIntRequired)?;
let n: i32 = n.try_into()?;
serial!(n, out)
} else {
Expand All @@ -141,7 +141,7 @@ fn write_bytes_from_json_schema_type<W: Write>(
}
Type::I64 => {
if let Value::Number(n) = json {
let n = n.as_u64().ok_or(JsonError::SignedIntRequired)?;
let n = n.as_i64().ok_or(JsonError::SignedIntRequired)?;
serial!(n, out)
} else {
Err(WrongJsonType("JSON number required".to_string()))
Expand Down

0 comments on commit 6e1e2fa

Please sign in to comment.