dpp/document/serialization_traits/json_conversion/
mod.rs1mod v0;
2
3pub use v0::*;
4
5use crate::document::{Document, DocumentV0};
6use crate::ProtocolError;
7use platform_value::Identifier;
8use platform_version::version::PlatformVersion;
9use serde::Deserialize;
10use serde_json::Value as JsonValue;
11use std::convert::TryInto;
12
13impl DocumentJsonMethodsV0<'_> for Document {
14 fn to_json_with_identifiers_using_bytes(
16 &self,
17 platform_version: &PlatformVersion,
18 ) -> Result<JsonValue, ProtocolError> {
19 match self {
20 Document::V0(v0) => v0.to_json_with_identifiers_using_bytes(platform_version),
21 }
22 }
23
24 fn to_json(&self, platform_version: &PlatformVersion) -> Result<JsonValue, ProtocolError> {
26 match self {
27 Document::V0(v0) => v0.to_json(platform_version),
28 }
29 }
30
31 fn from_json_value<S, E>(
33 document_value: JsonValue,
34 platform_version: &PlatformVersion,
35 ) -> Result<Self, ProtocolError>
36 where
37 for<'de> S: Deserialize<'de> + TryInto<Identifier, Error = E>,
38 E: Into<ProtocolError>,
39 {
40 match platform_version
41 .dpp
42 .document_versions
43 .document_structure_version
44 {
45 0 => Ok(Document::V0(DocumentV0::from_json_value::<S, E>(
46 document_value,
47 platform_version,
48 )?)),
49 version => Err(ProtocolError::UnknownVersionMismatch {
50 method: "Document::from_json_value".to_string(),
51 known_versions: vec![0],
52 received: version,
53 }),
54 }
55 }
56}