# Configurations.jl Read Vector of Multiple Possible Types from TOML File

**URL:** <https://discourse.julialang.org/t/configurations-jl-read-vector-of-multiple-possible-types-from-toml-file/107541>\
**Category:** General Usage\
**Tags:** configuration\
**Created:** [December 13, 2023, 12:53am UTC](https://discourse.julialang.org/t/configurations-jl-read-vector-of-multiple-possible-types-from-toml-file/107541 "2023-12-13T00:53:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew3245](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@matthew3245](https://discourse.julialang.org/u/matthew3245)\
**Post date:** [December 13, 2023, 12:53am UTC](https://discourse.julialang.org/t/configurations-jl-read-vector-of-multiple-possible-types-from-toml-file/107541/1 "2023-12-13T00:53:56Z")

</div>

Say that I have two custom option types, `TypeA` and `TypeB` defined below:

```julia
using Configurations

@option "type_a" struct TypeA
    type::Reflect
    a::Int
end

@option "type_b" struct TypeB
    type::Reflect
    b::Int
end

```

And I also have an option type that holds a vector of type `Union{TypeA, TypeB}`:

```julia
@option struct VectorType
    vec::Vector{Union{TypeA,TypeB}}
end

```

I’m am currently able to create a .toml file using this type as follows:

```julia
test_vec = VectorType([TypeA(Reflect(), 1), TypeB(Reflect(), 2)])
to_toml(joinpath(@ __DIR__ , "test.toml"), test_vec)

```

which creates test.toml as:

```julia
[[vec]]
type = "type_a"
a = 1

[[vec]]
type = "type_b"
b = 2

```

However I am unable to read the .toml back into my custom type:

```julia
test_vec = from_toml(VectorType, joinpath(@ __DIR__ , "test.toml"))

ERROR: ArgumentError: cannot parse type_a to a Julia type
Stacktrace:
  [1] parse_jltype(s::String, alias_map::Nothing)
    @ Configurations ~/.julia/packages/Configurations/Yxczn/src/utils.jl:46
  [2] macro expansion
    @ ~/.julia/packages/Configurations/Yxczn/src/from_dict.jl:430 [inlined]
  [3] from_dict_union_type(#unused#::Type{VectorType}, #unused#::OptionField{:vec}, #unused#::Type{Union{TypeA, TypeB}}, value::Dict{String, Any})
    @ Configurations ~/.julia/packages/Configurations/Yxczn/src/from_dict.jl:170
  [4] (::Configurations.var"#7#9"{VectorType, Vector{Union{TypeA, TypeB}}, OptionField{:vec}})(each::Dict{String, Any})
    @ Configurations ~/.julia/packages/Configurations/Yxczn/src/from_dict.jl:133
  [5] iterate
    @ ./generator.jl:47 [inlined]

```

Is this possible in the Configuration.jl package. Any help is appreciated.

Thanks!

@Roger-luo

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [December 13, 2023, 1:08am UTC](https://discourse.julialang.org/t/configurations-jl-read-vector-of-multiple-possible-types-from-toml-file/107541/2 "2023-12-13T01:08:58Z")

</div>

Err that looks like a bug lol. The `Union`s are not handled very well in the current implementation. I’ve created an issue but I prob won’t have much time fixing this for now.

---

<div class="post-metadata">

**Author:** ![matthew3245](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@matthew3245](https://discourse.julialang.org/u/matthew3245)\
**Post date:** [December 13, 2023, 1:24am UTC](https://discourse.julialang.org/t/configurations-jl-read-vector-of-multiple-possible-types-from-toml-file/107541/3 "2023-12-13T01:24:24Z")

</div>

Okay thanks for letting me know, I appreciate it.
