Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use serde::{Deserialize, Serialize}; // 1.0.88
- use serde_json; // 1.0.38
- #[derive(Debug, PartialEq, Serialize, Deserialize)]
- struct Application {
- application: Data,
- }
- #[derive(Debug, PartialEq, Serialize, Deserialize)]
- struct Data {
- build: String,
- container_name: String,
- environment: Environment,
- }
- use std::collections::BTreeMap;
- #[derive(Debug, PartialEq, Serialize, Deserialize)]
- #[serde(untagged)]
- enum Environment {
- Vec(Vec<String>),
- Hash(BTreeMap<String, String>),
- }
- fn main() {
- let content_vec = r#"
- {
- "application": {
- "build": "something",
- "container_name": "another_thing",
- "environment": [
- "ONE_ENV=fake",
- "SEC_ENV=somethingexample.yml"
- ]
- }
- }
- "#;
- let content_hash = r#"
- {
- "application": {
- "build": "something",
- "container_name": "another_thing",
- "environment": {
- "ONE_ENV": "fake",
- "SEC_ENV": "somethingexample.yml"
- }
- }
- }
- "#;
- let application_data: Application = serde_json::from_str(content_vec).unwrap();
- println!("{:?}", application_data.application.environment);
- let application_data: Application = serde_json::from_str(content_hash).unwrap();
- println!("{:?}", application_data.application.environment);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement