Skip to content

Issue when schema key having . (dot) in it #71

@Abn02

Description

@Abn02

when schema contains a key with dot in it
a field in UnmarshalJSON function creating with dot (.) in it and getting code errors

like template.hardwareIdReceived := false in below snippet

func (strct *Attrs) UnmarshalJSON(b []byte) error {
    template.hardwareIdReceived := false
    var jsonMap map[string]json.RawMessage
    if err := json.Unmarshal(b, &jsonMap); err != nil {
        return err
    }
    // parse all the defined properties
    for k, v := range jsonMap {
        switch k {
        case "template.hardwareId":
            if err := json.Unmarshal([]byte(v), &strct.TemplateHardwareId); err != nil {
                return err
             }
            template.hardwareIdReceived = true
        }
    }
    // check if template.hardwareId (a required property) was received
    if !template.hardwareIdReceived {
        return errors.New("\"template.hardwareId\" is required but was not present")
    }
    return nil
}

is there any way to avoid it ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions