Skip to content

Commit

Permalink
Merge pull request #395 from flaviocirillo/development
Browse files Browse the repository at this point in the history
Fixed bug on marshalling golang struct
  • Loading branch information
smartfog committed Nov 18, 2022
2 parents be83238 + 7b0f9e6 commit 3ba9930
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 6 additions & 8 deletions common/ngsi/ngsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ func (queryCtxResp *QueryContextResponse) parseQueryContextResponse_HybridNGSI_N

queryCtxRespInternal := InternalQueryContextResponseObject{}
_ = json.Unmarshal(queryResponseBody, &queryCtxRespInternal)
// DEBUG.Println(queryCtxRespInternal)
// err := json.Unmarshal(queryResponseBody, &queryCtxRespInternal)
// if err != nil {
// ERROR.Println(err)
Expand All @@ -1035,6 +1036,7 @@ func (queryCtxResp *QueryContextResponse) parseQueryContextResponse_HybridNGSI_N

parsedQueryCtxResp := QueryContextResponse{}
_ = json.Unmarshal(queryResponseBody, &parsedQueryCtxResp)
// DEBUG.Println(parsedQueryCtxResp)
// err = json.Unmarshal(queryResponseBody, &parsedQueryCtxResp)
// if err != nil {
// ERROR.Println(err)
Expand Down Expand Up @@ -1062,9 +1064,10 @@ func (queryCtxResp *QueryContextResponse) parseQueryContextResponse_HybridNGSI_N

ctxElement := ContextElement{}
ctxElement.Entity = ctxRespInternal.ContextElement.Entity
ctxElement.ID = ctxRespInternal.ContextElement.Entity.ID
ctxElement.Type = ctxRespInternal.ContextElement.Type
ctxElement.IsPattern = ctxRespInternal.ContextElement.IsPattern
//ctxElement.ID = ctxRespInternal.ContextElement.Entity.ID
ctxElement.Entity = (parsedQueryCtxResp.ContextResponses)[ctxResp_index].ContextElement.Entity
//ctxElement.Type = ctxRespInternal.ContextElement.Type
//ctxElement.IsPattern = ctxRespInternal.ContextElement.IsPattern
ctxElement.Metadata = ctxRespInternal.ContextElement.Metadata
ctxElement.Attributes = make([]ContextAttribute, 0)

Expand All @@ -1078,8 +1081,6 @@ func (queryCtxResp *QueryContextResponse) parseQueryContextResponse_HybridNGSI_N
if attributeInternal.Value != nil {
ctxAttribute.Value = attributeInternal.Value
} else {
// DEBUG.Println((parsedQueryCtxResp.ContextResponses)[ctxResp_index])
// DEBUG.Println(((parsedQueryCtxResp.ContextResponses)[ctxResp_index].ContextElement.Attributes)[attribute_index])
ctxAttribute.Value = ((parsedQueryCtxResp.ContextResponses)[ctxResp_index].ContextElement.Attributes)[attribute_index].Value
}

Expand All @@ -1092,9 +1093,6 @@ func (queryCtxResp *QueryContextResponse) parseQueryContextResponse_HybridNGSI_N
}

queryCtxResp.ContextResponses = contextResponses

// DEBUG.Println(queryCtxResp)

}

func (updateCtxReq *UpdateContextRequest) ReadFromNGSIv2(ngsiv2Entity map[string]interface{}) int {
Expand Down
5 changes: 0 additions & 5 deletions common/ngsi/ngsiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,16 @@ func (nc *NGSI10Client) InternalQueryContext(query *QueryContextRequest) ([]Cont
}

text, _ := ioutil.ReadAll(resp.Body)
// DEBUG.Println(string(text))

// queryCtxResp := QueryContextResponse{}
// err = json.Unmarshal(text, &queryCtxResp)
// if err != nil {
// return nil, err
// }

// DEBUG.Println(queryCtxResp)

queryCtxResp := QueryContextResponse{}
queryCtxResp.parseQueryContextResponse_HybridNGSI_NGSILD(text)

// DEBUG.Println(queryCtxResp)

ctxElements := make([]ContextElement, 0)
for _, contextElementResponse := range queryCtxResp.ContextResponses {
ctxElements = append(ctxElements, contextElementResponse.ContextElement)
Expand Down

0 comments on commit 3ba9930

Please sign in to comment.