diff --git a/src/json2object/writer/DataBuilder.hx b/src/json2object/writer/DataBuilder.hx index b7034fb..4016a79 100644 --- a/src/json2object/writer/DataBuilder.hx +++ b/src/json2object/writer/DataBuilder.hx @@ -210,11 +210,22 @@ class DataBuilder { } assignations.push(assignation); - skips.push( - field.meta.has(':optional') - ? macro $f_a == null - : macro false - ); + if (field.meta.has(':optional')) { + switch (field.type) { + case TAbstract(t, params): + if (t.toString() == "Null") { + // Null + skips.push(macro $f_a == null); + } else { + // Bool + skips.push(macro false); + } + default: + skips.push(macro $f_a == null); + } + } else { + skips.push(macro false); + } default: }