@@ -368,6 +368,7 @@ func writeTypes(f *os.File, typeCollection []TypeTemplate, typeValidationCollect
368368 // Check the discriminator to decide which type to unmarshal to.
369369 fmt .Fprintf (f , "\t var peek struct {\n " )
370370 fmt .Fprintf (f , "\t \t Discriminator %s `json:\" %s\" `\n " , tt .DiscriminatorType , tt .DiscriminatorKey )
371+ fmt .Fprintf (f , "\t \t Value json.RawMessage `json:\" %s\" `\n " , strings .ToLower (tt .VariantField ))
371372 fmt .Fprintf (f , "\t }\n " )
372373 fmt .Fprintf (f , "\t if err := json.Unmarshal(data, &peek); err != nil {\n " )
373374 fmt .Fprintf (f , "\t \t return err\n " )
@@ -380,17 +381,14 @@ func writeTypes(f *os.File, typeCollection []TypeTemplate, typeValidationCollect
380381
381382 // For objects, unmarshal into the corresponding struct. For simple types, unmarshal into a temporary struct, then grab the value from it.
382383 if isSimpleType (mapping .ObjectType ) {
383- fmt .Fprintf (f , "\t \t type value struct {\n " )
384- fmt .Fprintf (f , "\t \t \t Value %s `json:\" %s\" `\n " , mapping .ConcreteType , strings .ToLower (tt .VariantField ))
385- fmt .Fprintf (f , "\t \t }\n " )
386- fmt .Fprintf (f , "\t \t var val value\n " )
387- fmt .Fprintf (f , "\t \t if err := json.Unmarshal(data, &val); err != nil {\n " )
384+ fmt .Fprintf (f , "\t \t var val %s\n " , mapping .ConcreteType )
385+ fmt .Fprintf (f , "\t \t if err := json.Unmarshal(peek.Value, &val); err != nil {\n " )
388386 fmt .Fprintf (f , "\t \t \t return err\n " )
389387 fmt .Fprintf (f , "\t \t }\n " )
390- fmt .Fprintf (f , "\t v.%s = val.Value \n " , tt .VariantField )
388+ fmt .Fprintf (f , "\t v.%s = val\n " , tt .VariantField )
391389 } else {
392390 fmt .Fprintf (f , "\t \t var val %s\n " , mapping .ConcreteType )
393- fmt .Fprintf (f , "\t \t if err := json.Unmarshal(data , &val); err != nil {\n " )
391+ fmt .Fprintf (f , "\t \t if err := json.Unmarshal(peek.Value , &val); err != nil {\n " )
394392 fmt .Fprintf (f , "\t \t \t return err\n " )
395393 fmt .Fprintf (f , "\t \t }\n " )
396394 fmt .Fprintf (f , "\t v.%s = val\n " , tt .VariantField )
0 commit comments