Ensure arrays and objects serialize correctly
This commit is contained in:
parent
9ae2cc7cd1
commit
1f9cad9431
1 changed files with 22 additions and 1 deletions
|
@ -8,7 +8,9 @@ use crate::sql::literal::Literal;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
const NAME: &'static str = "Value";
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Deserialize)]
|
||||
pub enum Value {
|
||||
Literal(Literal),
|
||||
Expression(Expression),
|
||||
|
@ -54,3 +56,22 @@ impl dbs::Process for Value {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Value {
|
||||
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if s.is_human_readable() {
|
||||
match self {
|
||||
Value::Literal(ref v) => s.serialize_some(v),
|
||||
Value::Expression(ref v) => s.serialize_some(v),
|
||||
}
|
||||
} else {
|
||||
match self {
|
||||
Value::Literal(ref v) => s.serialize_newtype_variant(NAME, 0, "Literal", v),
|
||||
Value::Expression(ref v) => s.serialize_newtype_variant(NAME, 1, "Expression", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue