questions: remove "skip_serializing_if"
All checks were successful
continuous-integration/drone/push Build is passing

to fix ser/de to postcard

err "Hit the end of buffer, expected more data"
more info: https://github.com/apache/arrow-rs/issues/3082
This commit is contained in:
Dmitry Belyaev 2023-08-23 23:50:31 +03:00
parent 85a879e9ec
commit e4001ee69f

View File

@ -2,83 +2,71 @@ use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct BatchInfo { pub struct BatchInfo {
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub filename: String, pub filename: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub description: String, pub description: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub author: String, pub author: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub comment: String, pub comment: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub url: String, pub url: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub date: String, pub date: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub processed_by: String, pub processed_by: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub redacted_by: String, pub redacted_by: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub copyright: String, pub copyright: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub theme: String, pub theme: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub kind: String, pub kind: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub source: String, pub source: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub rating: String, pub rating: String,
} }
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct Question { pub struct Question {
#[serde(default, skip_serializing_if = "u32_is_zero")] #[serde(default)]
pub num: u32, pub num: u32,
pub id: String, pub id: String,
pub description: String, pub description: String,
pub answer: String, pub answer: String,
#[serde(default)]
#[serde(default, skip_serializing_if = "String::is_empty")]
pub author: String, pub author: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub comment: String, pub comment: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub comment1: String, pub comment1: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub tour: String, pub tour: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub url: String, pub url: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub date: String, pub date: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub processed_by: String, pub processed_by: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub redacted_by: String, pub redacted_by: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub copyright: String, pub copyright: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub theme: String, pub theme: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub kind: String, pub kind: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub source: String, pub source: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default)]
pub rating: String, pub rating: String,
#[serde(default, skip_serializing_if = "BatchInfo::is_default")] #[serde(default)]
pub batch_info: BatchInfo, pub batch_info: BatchInfo,
} }
fn u32_is_zero(num: &u32) -> bool {
*num == 0
}
impl BatchInfo {
pub fn is_default(&self) -> bool {
*self == BatchInfo::default()
}
}
#[cfg(any(feature = "convert", feature = "convert_async"))] #[cfg(any(feature = "convert", feature = "convert_async"))]
pub mod convert_common { pub mod convert_common {
use super::{BatchInfo, Question}; use super::{BatchInfo, Question};
@ -170,20 +158,68 @@ pub mod convert {
let converted: Vec<_> = source.convert().collect(); let converted: Vec<_> = source.convert().collect();
assert_yaml_snapshot!(converted, @r#" assert_yaml_snapshot!(converted, @r#"
--- ---
- id: Вопрос 1 - num: 0
id: Вопрос 1
description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2
answer: "42" answer: "42"
author: ""
comment: ""
comment1: ""
tour: ""
url: ""
date: ""
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
batch_info: batch_info:
filename: test.json filename: test.json
description: Тестовый description: Тестовый
author: ""
comment: ""
url: ""
date: 00-000-2000 date: 00-000-2000
- id: Вопрос 2 processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
- num: 0
id: Вопрос 2
description: Зимой и летом одним цветом description: Зимой и летом одним цветом
answer: ёлка answer: ёлка
author: ""
comment: ""
comment1: ""
tour: ""
url: ""
date: ""
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
batch_info: batch_info:
filename: test.json filename: test.json
description: Тестовый description: Тестовый
author: ""
comment: ""
url: ""
date: 00-000-2000 date: 00-000-2000
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
"#); "#);
} }
@ -285,20 +321,68 @@ pub mod convert_async {
let converted: Vec<_> = converter.collect().await; let converted: Vec<_> = converter.collect().await;
assert_yaml_snapshot!(converted, @r#" assert_yaml_snapshot!(converted, @r#"
--- ---
- id: Вопрос 1 - num: 0
id: Вопрос 1
description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2
answer: "42" answer: "42"
author: ""
comment: ""
comment1: ""
tour: ""
url: ""
date: ""
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
batch_info: batch_info:
filename: test.json filename: test.json
description: Тестовый description: Тестовый
author: ""
comment: ""
url: ""
date: 00-000-2000 date: 00-000-2000
- id: Вопрос 2 processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
- num: 0
id: Вопрос 2
description: Зимой и летом одним цветом description: Зимой и летом одним цветом
answer: ёлка answer: ёлка
author: ""
comment: ""
comment1: ""
tour: ""
url: ""
date: ""
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
batch_info: batch_info:
filename: test.json filename: test.json
description: Тестовый description: Тестовый
author: ""
comment: ""
url: ""
date: 00-000-2000 date: 00-000-2000
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
"#); "#);
} }
@ -358,12 +442,37 @@ mod test {
fn test_question_ser() { fn test_question_ser() {
assert_yaml_snapshot!(sample_question(), @r#" assert_yaml_snapshot!(sample_question(), @r#"
--- ---
num: 0
id: Вопрос 1 id: Вопрос 1
description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2
answer: "42" answer: "42"
author: ""
comment: ""
comment1: ""
tour: ""
url: ""
date: ""
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
batch_info: batch_info:
filename: ""
description: Тестовый description: Тестовый
author: ""
comment: ""
url: ""
date: 00-000-2000 date: 00-000-2000
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
"#); "#);
} }
@ -382,12 +491,37 @@ mod test {
assert_yaml_snapshot!(question_from_json.unwrap(), @r#" assert_yaml_snapshot!(question_from_json.unwrap(), @r#"
--- ---
num: 0
id: Вопрос 1 id: Вопрос 1
description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2
answer: "42" answer: "42"
author: ""
comment: ""
comment1: ""
tour: ""
url: ""
date: ""
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
batch_info: batch_info:
filename: ""
description: Тестовый description: Тестовый
author: ""
comment: ""
url: ""
date: 00-000-2000 date: 00-000-2000
processed_by: ""
redacted_by: ""
copyright: ""
theme: ""
kind: ""
source: ""
rating: ""
"#); "#);
} }