From 2f4570d0fa3b507709e5f849ffd1139d41fbc2c4 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 24 Jun 2023 21:40:38 +0200 Subject: [PATCH] Deserializer - Added `string[]` (`string`-array) deserialization support Unittests - Added string array example test --- source/jstruct/deserializer.d | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/jstruct/deserializer.d b/source/jstruct/deserializer.d index 8a5bdc5..09781c5 100644 --- a/source/jstruct/deserializer.d +++ b/source/jstruct/deserializer.d @@ -162,6 +162,10 @@ public RecordType fromJSON(RecordType)(JSONValue jsonIn) { mixin("record."~structNames[cnt])~= cast(double)jsonVal.floating(); } + else static if(__traits(isSame, ForeachType!(structTypes[cnt]), string)) + { + mixin("record."~structNames[cnt])~= jsonVal.str(); + } @@ -187,6 +191,7 @@ public RecordType fromJSON(RecordType)(JSONValue jsonIn) } catch(JSONException e) { + // TOOD: Should be DEserialization error throw new SerializationError(); } } @@ -213,6 +218,7 @@ unittest public bool[] list2; public float[] list3; public double[] list4; + public string[] list5; } JSONValue json = parseJSON(`{ @@ -224,7 +230,8 @@ unittest "list": [1,2,3], "list2": [true, false], "list3": [1.5, 1.4], -"list4": [1.5, 1.4] +"list4": [1.5, 1.4], +"list5": ["baba", "booey"] } `); @@ -244,6 +251,8 @@ unittest assert(person.list2 == [true, false]); assert(person.list3 == [1.5F, 1.4F]); assert(person.list4 == [1.5, 1.4]); + assert(person.list5 == ["baba", "booey"]); + } /**