From ad7ac005d0808172a9bcbca7f5b62e879cfa0e6e Mon Sep 17 00:00:00 2001 From: lostbean Date: Fri, 29 Nov 2024 22:51:08 -0300 Subject: [PATCH] bypass decode error --- gleam.toml | 2 +- src/json/blueprint.gleam | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/gleam.toml b/gleam.toml index cc550b1..39aaafb 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "json_blueprint" -version = "1.2.1" +version = "1.2.2" description = "Simplify JSON encoding/decoding while automatically generating JSON schemas for your data types." licences = ["MIT"] diff --git a/src/json/blueprint.gleam b/src/json/blueprint.gleam index 41651e9..fff47d9 100644 --- a/src/json/blueprint.gleam +++ b/src/json/blueprint.gleam @@ -137,10 +137,10 @@ pub fn union_type_decoder( ) { decoders |> list.find_map(fn(dec) { - case dec { - #(name, d) if type_str == name -> { - let #(dyn_decoder, _) = d - dyn_decoder(data) + case dec.0 == type_str { + True -> { + let #(dyn_decoder, _) = dec.1 + Ok(dyn_decoder(data)) } _ -> Error([]) } @@ -157,6 +157,7 @@ pub fn union_type_decoder( ), ] }) + |> result.flatten } let enum_decoder = fn(data) {