@@ -59,23 +59,21 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
5959 { {#composedSchemas.oneOf} }
6060 { {#dataType} }
6161 // try to unmarshal data into { {#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} }
62- err = json.Unmarshal(data, &dst.{ {#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} })
62+ dst{ {classname} }{ {-index} } := & { {classname} }{ }
63+ err = json.Unmarshal(data, &dst{ {classname} }{ {-index} }.{ {#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} })
6364 if err == nil {
64- json{{{.} }}, _ := json.Marshal(dst.{ {#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} })
65+ json{{{.} }}, _ := json.Marshal(& dst{ {classname } } { {-index } } .{ {#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} })
6566 { {#pattern} }
6667 regex := `{ {.} }`
6768 regex = regexp.MustCompile("^\\/|\\/$").ReplaceAllString(regex, "$1") // Remove beginning slash and ending slash
6869 regex = regexp.MustCompile("\\\\(.)").ReplaceAllString(regex, "$1") // Remove duplicate escaping char for dots
69- rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dst.String , "$1") // Remove quotes
70+ rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dst{ {classname } } { {-index } }. { {#lambda.type-to-name } } { {dataType } } { {/lambda.type-to-name } } , "$1") // Remove quotes
7071 isMatched, _ := regexp.MatchString(regex, rawString)
7172 { {/pattern} }
72- if string(json{ {{.} }}) == "{ } " { {#pattern} }|| !isMatched { {/pattern} } { // empty struct
73- dst.{{#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} } = nil
74- } else {
73+ if string(json{ {{.} }}) != "{ } " { {#pattern} }&& isMatched { {/pattern} } { // empty struct
74+ dst.{{#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} } = dst{ {classname} }{ {-index} }.{ {#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} }
7575 match++
7676 }
77- } else {
78- dst.{{#lambda.type-to-name} }{ {{.} }}{ {/lambda.type-to-name} } = nil
7977 }
8078
8179 { {/dataType} }
0 commit comments