libmir/asdf

Deserialize an array with different element types

bagomot opened this issue · 2 comments

I have the following json node (jvm):

{
    "jvm":[
        {
            "rules":[
               {
                    "action":"allow",
                    "os":{
                        "arch":"x86"
                    }
               }
            ],
            "value":"-Xss1M"
        },
         "-Djava.library.path=${natives_directory}"
    ]
}

Here the node elements can be either a string or an object.
How do I deserialize this node?
I tried something like:

import std.sumtype;
import asdf;

struct Jvm { 
    SumType!(JvmArgument, string) data;
    alias data this;

    SerdeException deserializeFromAsdf(Asdf data) { 
        string val;
        if (auto exc = deserializeScopedString(data, val))
            return exc;

        this = ???

        return null; 
    }
}

struct JvmArgument {
    @serdeKeys("rules")
    Rule[] rule;
    @serdeKeys("value")
    string[] value;
}

struct Rule{
    @serdeKeys("action") 
    string action;
    @serdeKeys("os")
    @serdeOptional
    Os os;
}

I don't understand how to fill in "this" in this case.
Do you have any ideas?

9il commented

Mir libraries doesn't support symtype. Check http://mir-core.libmir.org/mir_algebraic.html

I am not sure it will just work.

At lest, http://mir-algorithm.libmir.org/mir_algebraic_alias_json.html will work in the other way.

Thanks, I will try with mir_algebraic. Hope to see support for sumtype in the future.