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