michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
412 stars 114 forks source link

Json Convert Error for All Lights #211

Closed talun2075 closed 4 years ago

talun2075 commented 4 years ago

Hi, I got on my MVC API an Error, if I return the Result of "UseClient.GetLightsAsync()" All others like Groups works well. Every Time I want to call a Phillips Light I got Errors. If I call a Light like my Osram PowerPlug it works fine.

The Exception is a: Newtonsoft.Json.JsonWriterException The Error I got is Q42.HueApi\Converters\GamutConverter.cs:Zeile 71

Maybe You can Help me why I got a Serilisation error.

michielpost commented 4 years ago

Can you post the json that the app receives from the bridge? Maybe get it with a tool like Fiddler.

talun2075 commented 4 years ago

I have look a little bit more in it. I have create a new class Based on Light and override the Property Capabilities. Then all works fine.

To understand it right. The Code from you works on c#. I got all in fine objects and can work with them but if I want to give it to my UI the MVC API convert it in Json an there is the problem.

I Attach the raw Response from the Bridge and hope it will help.

Thanks

JsonResponseForAllLights.txt

michielpost commented 4 years ago

This does not look like a problem with Q42.HueApi. Are you using the Newtonsoft JsonConverter or the new System.Text.Json included with asp.net core 3.2? The current models work with the Newtonsoft converter. If you want to create json models for your UI, a good practice is to use your own models.

Mephistofeles commented 4 years ago

It is an error in GamutConverter. JsonSerializer should be used instead of writing List<List> using JsonWriter, which is unsupported.

michielpost commented 4 years ago

Fix has been deployed to NuGet with version 3.15.1