This is an automated email from the ASF dual-hosted git repository. sruehl pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 5412078660887a31ee6d8ab62bf13e75bfe323f7 Author: Sebastian Rühl <sru...@apache.org> AuthorDate: Wed Sep 4 22:05:18 2024 +0200 feat(plc4go/plc4xGenerator): nil safe directSerialize --- plc4go/tools/plc4xGenerator/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plc4go/tools/plc4xGenerator/main.go b/plc4go/tools/plc4xGenerator/main.go index c97936e6c6..87214eb2a4 100644 --- a/plc4go/tools/plc4xGenerator/main.go +++ b/plc4go/tools/plc4xGenerator/main.go @@ -300,7 +300,15 @@ func (g *Generator) generate(typeName string) { continue } if field.directSerialize { - g.Printf(serializableDirectFieldTemplate, "d."+field.name+"", fieldNameUntitled) + indentTimes := 0 + if needsDereference { + indentTimes++ + g.Printf("if d.%s != nil {", field.name) + } + g.Printf(indent(indentTimes, serializableDirectFieldTemplate), "d."+field.name+"", fieldNameUntitled) + if needsDereference { + g.Printf("}\n") + } continue } switch fieldType := fieldType.(type) {