BHoM / BHoM/BHoM_Engine

Serialiser_Engine: JSON Deserializing RenderMesh > System.Drawing.Color

Open
#2,185 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
30
Forks
13
Avg merge
7d 10h
Merged PRs (30d)
5

Description

I am trying to test the "Scheduler" aspect of BHoM and requested a json data dump of a Revit file. I am trying to deserialize the json into a `BH.oM.Base.BHoMObject` but there are aspects which aren't deserializing properly.

#### Description:
Within the Graphic_oM > Render > RenderMesh I am iterating the custom data via:
```
foreach (KeyValuePair ca in o.CustomData)
{
if (ca.Key == "RenderMesh")
{
```

The error I receive is:

> Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Drawing.Color' because the type requires a JSON string value to deserialize correctly.
> To fix this error either change the JSON to a JSON string value or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
> Path '[0].Vertices[0].Color.A', line 13, position 12.

This is a well documented issue:
[https://stackoverflow.com/questions/27584530/json-net-serialization-of-system-drawing-color-with-typenamehandling](url)
[https://stackoverflow.com/questions/24502847/javascriptserializer-is-not-deserializing-system-drawing-color-how-to-deseriali](url)
[https://ratborg.blogspot.com/2017/07/colorful-serialization.html](url)

This is based on deserializing a .NET object not a BHoM object, so I think that some JSON and XML declaration attributes need to be created to remedy this.

#### Steps to reproduce:
Change the file extension from '.txt' to 'json' and this reveals the location of the error, as per the message above.
[Graphics RenderMesh.txt](https://github.com/BHoM/BHoM/files/4672514/Graphics.RenderMesh.txt)

#### Expected behaviour:
It should deserialize correctly

#### Test file(s):
See steps to reproduce

Contributor guide

Open the contributing guide

Research direction

Start with the attached Graphics RenderMesh.txt, renamed to .json, and trace deserialization at [0].Vertices[0].Color.A in the RenderMesh custom data. Compare the JSON representation with the System.Drawing.Color type and verify that the RenderMesh data deserializes correctly into a BH.oM.Base.BHoMObject.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.