ift-gftc / opentraceability

A repository for storing code for the open source traceability libraries developed by IFT.
MIT License
4 stars 2 forks source link

Fixing error with JSON string #28

Open MarceloWholechain opened 9 months ago

MarceloWholechain commented 9 months ago

When using the MasterDataResolver in wholechain, we ran in the following issue:

Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path '', line 1, position 1165.
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json)
   at OpenTraceability.Mappers.MasterData.GS1VocabJsonMapper.Map(Type type, String value)
   at OpenTraceability.Queries.MasterDataResolver.ResolveMasterDataItem(Type type, DigitalLinkQueryOptions options, String relativeURL, HttpClient httpClient)

It seems that it's keeping the \r\n instead of converting to JSON. The issue happens on the line below on the GS1VocabJsonMapper:

JObject json = JObject.Parse(value);

It was fixed by reading the response from the digital link as JSON.