Skip to content

Commit

Permalink
Fix serialisation bug with one-field json
Browse files Browse the repository at this point in the history
  • Loading branch information
not-fl3 committed Jul 20, 2020
1 parent ceab998 commit 0704316
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nanoserde"
version = "0.1.17"
version = "0.1.18"
authors = ["makepad <[email protected]>", "Fedor <[email protected]>"]
license = "MIT OR Apache-2.0"
description = """
Expand All @@ -22,4 +22,4 @@ edition = "2018"
repository = "https://github.com/not-fl3/nanoserde"

[dependencies]
nanoserde-derive = { path = "derive", version = "=0.1.11" }
nanoserde-derive = { path = "derive", version = "=0.1.12" }
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nanoserde-derive"
version = "0.1.11"
version = "0.1.12"
authors = ["Makepad <[email protected]>", "Fedor <[email protected]>"]
edition = "2018"
description = "Fork of makepad-tinyserde derive without any external dependencies"
Expand Down
2 changes: 1 addition & 1 deletion derive/src/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn derive_ser_json_proxy(proxy_type: &str, type_: &str) -> TokenStream {
pub fn derive_ser_json_struct(struct_: &Struct) -> TokenStream {
let mut s = String::new();

if struct_.fields.len() > 1 {
if struct_.fields.len() >= 1 {
let last = struct_.fields.len() - 1;
for (index, field) in struct_.fields.iter().enumerate() {
let struct_fieldname = field.field_name.clone().unwrap();
Expand Down
13 changes: 13 additions & 0 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ fn empty() {
let _: Empty = DeJson::deserialize_json(json).unwrap();
}

#[test]
fn one_field() {
#[derive(DeJson, SerJson, PartialEq)]
pub struct OneField {
field: f32,
}

let test = OneField { field: 23. };
let bytes = SerJson::serialize_json(&test);
let test_deserialized = DeJson::deserialize_json(&bytes).unwrap();
assert!(test == test_deserialized);
}

#[test]
fn array() {
#[derive(DeJson)]
Expand Down

0 comments on commit 0704316

Please sign in to comment.