-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Is there any way to serialize a structure like this?
{
"kinds" : [
{
"name": "name_1",
"role": "Test"
},
{
"name": "name_2",
"role": { "Check": 1 }
},
{
"name": "name_3",
"role": { "Check": 2 }
}
]
}
For example, with rust serde we can use a enum like the one bellow to serialize/deserialize the "role" field
#[derive(Serialize, Deserialize)]
pub enum Role {
Test,
Check(i32),
}
But the following schema will fail, of course
kind_schema <-
s_map(
name = s_string(),
role = s_map(
Check = s_integer()
)
)
schema <-
s_map(
kind = s_vector(kind_schema)
) |>
build_structure()
list(
kind = list(
list(
name = "name_1",
role = list(
Check = 1L
)
),
list(
name = "name_2",
role = list(
Check = 2L
)
),
list(
name = "name_3",
role = "Test"
)
)
) |>
serialize_json(schema, pretty = TRUE)
Is it possible to handle the { "role": "Test" } case together with { "role" : {"Check": 1} } ?
Metadata
Metadata
Assignees
Labels
No labels