Property of type object not serialized properly above v9.0.1
See original GitHub issueHi,
I’m having problems with serialization inside my Azure function project. This is a default Azure Function project inside VS2017 which comes with Newtonsoft.Json 9.0.1.
I’m working with a queue triggered function but this itself is not relevant for the problem.
public static void Run([QueueTrigger("queue")] Notification message, TraceWriter log)
{
log.Info($"{JsonConvert.SerializeObject(message)}");
}
Notification type
public class Notification
{
public string Target { get; set; }
public Guid Uid { get; set; }
public string Topic { get; set; }
public ServiceTypes ServiceType { get; set; }
public string HubSecret { get; set; }
public DateTime Created { get; set; }
public DateTime? FirstSentAt { get; set; }
public IEnumerable<NotificationItem> Payload { get; set; }
}
public class NotificationItem
{
public string Type { get; set; }
public object Data { get; set; }
}
Source JSON
When function is triggered by a new item from the queue the JSON is properly deserialized into Notification object
Here’s the JSON from the queue:
{
"Target": "https://test.com",
"Uid": "00000000-0000-0000-0000-000000000000",
"Topic": "action.moved",
"ServiceType": "Inbox",
"CompanyId": "00000000-0000-0000-0000-000000000000",
"Created": "2018-06-17T20:24:16.5534423Z",
"FirstSentAt": null,
"Payload": [
{
"Type": "actionsubject",
"Data": {
"Skills": [
],
"Tags": [
"tag1",
"tag2"
],
"Emails": [
{
"Id": 111111,
"Value": "john.doe@gmail.com",
"Type": "email"
}
],
"PhoneNumbers": [
{
"Id": 222222,
"Value": "5555555555",
"Type": "phone"
}
],
"SocialNetworks": [
{
"Id": 3333333,
"Value": "www.facebook.com",
"Type": "other"
}
],
"PossibleDuplicates": true,
"Id": 123456,
"FirstName": "John",
"LastName": "Doe",
"Name": "John Doe",
"Title": null,
"Avatar": null,
"Company": null,
"Created": "2018-04-04T22:20:27.307",
"Uid": "00000000-0000-0000-0000-000000000000"
}
}
]
}
After serialization inside the function:
{
"Target": "https://test.com",
"Uid": "00000000-0000-0000-0000-000000000000",
"Topic": "action.moved",
"ServiceType": 3,
"HubSecret": null,
"CompanyId": "00000000-0000-0000-0000-000000000000",
"Created": "2018-06-17T20:24:16.5534423Z",
"FirstSentAt": null,
"Payload": [
{
"Type": "actionsubject",
"Data": {
"Skills": [
],
"Tags": [
[
],
[
]
],
"Emails": [
{
"Id": [
],
"Value": [
],
"Type": [
]
}
],
"PhoneNumbers": [
{
"Id": [
],
"Value": [
],
"Type": [
]
}
],
"SocialNetworks": [
{
"Id": [
],
"Value": [
],
"Type": [
]
}
],
"PossibleDuplicates": [
],
"Id": [
],
"FirstName": [
],
"LastName": [
],
"Name": [
],
"Title": [
],
"Avatar": [
],
"Company": [
],
"Created": [
],
"Uid": [
]
}
}
],
"Subscription": null
}
As you can see, all the NotificationItem.Data properties of the Payload array are being serialized as empty arrays. This happens in versions of Newtonsof.Json higher than 9.0.1. 9.0.1 serializes the object as expected.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Newtonsoft serialization of object with few not serializable ...
I have no control over currentObject because the actual code is part of a logging utility, and so 'currentObject' could be everything the ......
Read more >Source serialization | Elasticsearch .NET Client [8.9]
The default behaviour is to serialize type property names as camelcase JSON object members. We can model documents using a regular class (POCO)....
Read more >How to serialize properties of derived classes with System. ...
In this article, you will learn how to serialize properties of derived classes with the System. Text. Json namespace.
Read more >Serializing Data
Learn how to serialize and deserialize data on Solana. ... Flexible class that takes properties and imbues them // to the object instance ......
Read more >Custom serialization and deserialization contracts
The converter will serialize the type into a JSON object and uses its properties. This kind is used for most class and struct...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Not yet
@tmoon8730 I wrote in my original post that this occurs whenever using a Newtonsoft version higher than the project default (9.0.1 for Function v1, 10.0.3 for Function v2). If you find out why this happens, please do notify us. I Gues @JamesNK accepts PR’s.