You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2024/09/04 20:54:39 UTC

(plc4x) 04/05: feat(plc4go/plc4xGenerator): nil safe directSerialize

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 <sr...@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) {