Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to deserialize the sparkplug metric via System.Text.Json or Newtonsoft.Json. #98

Open
malavvvakharia opened this issue May 21, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@malavvvakharia
Copy link

malavvvakharia commented May 21, 2024

For example below is the one example of JSON which I need to deserialize to List:

Example:

`[
  {
    "Name": "configuration/ABC",
    "Alias": null,
    "Timestamp": null,
    "IsHistorical": null,
    "IsTransient": null,
    "IsNull": false,
    "MetaData": null,
    "Properties": null,
    "Value": {
      "Version": "",
      "Metrics": [
        {
          "Name": "product",
          "Alias": null,
          "Timestamp": null,
          "IsHistorical": null,
          "IsTransient": null,
          "IsNull": false,
          "MetaData": null,
          "Properties": null,
          "Value": "ABC",
          "DataType": 12
        }
      ],
      "Parameters": [
        
      ],
      "TemplateRef": "",
      "IsDefinition": null
    },
    "DataType": 19
  }
]`

C# code:

var metric = JsonConvert.DeserializeObject<List<Metric>>(metrics); var metric = System.Text.Json.JsonSerializer.Deserialize<List<Metric>>(metrics);

Now after deserialize, it will give value as null.

image

@SeppPenner SeppPenner self-assigned this Jul 2, 2024
@SeppPenner
Copy link
Owner

What is metrics and where does it come from? The library is just there to serialize / deserialize data to / from Protobuf and to conveniently work with Sparkplug / Protobuf logic, but isn't optimized for JSON serialization (And I guess with the current model, this isn't even possible)...

@SeppPenner SeppPenner added the question Further information is requested label Jul 2, 2024
@SeppPenner
Copy link
Owner

In my opinion, this shouldn't be part of the library as e.g. Annotations for System.Text.Json / Newtonsoft.Json would pollute the data models while the use case in the library is only Protobuf, not JSON...

@SeppPenner
Copy link
Owner

I might try something though. (Maybe extension packages).

@SeppPenner SeppPenner reopened this Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants