net-core-push-notifications icon indicating copy to clipboard operation
net-core-push-notifications copied to clipboard

message.data serialization convention

Open co-dax opened this issue 2 years ago • 3 comments

If I am not missing something in v3 the object assigned to message.data was getting serialized with property names as they are specified in the object but now in v4 if the objects names are converted to camelCase making them start with the lowecase letters. Pehaps we could keep the same convention as before?

co-dax avatar Mar 15 '23 16:03 co-dax

Good question. You can pass a different serializer into the senders. Just override it here:

https://github.com/andrei-m-code/net-core-push-notifications/blob/4f46d6003e2f8920890d69bf5cbd4e4931db3a20/CorePush/Serialization/DefaultCorePushJsonSerializer.cs#L24

The motivation behind having it camel case is that firebase and apple expects lower case fields so it's easier to just have everything converted to lower case..

More input on this is appreciated

andrei-m-code avatar Mar 15 '23 16:03 andrei-m-code

Yeah, it makes sense making everything uniform with regards to letter casing now it is only question if that outweights the fact that one is not getting at the device what he sends from the backend meaning if someone sends PascalCase then he might have a good reason for that. For example I am using C# and Angular and I have a plugin that is automatically creating all TypeScript files from the frontend based on the entities from the backend so for the for the message.data object I use a class with PascalCase properties and on the frontend I have (automatically generated as I mentioned above) TypeScript interface with the identic PascalCase properties but as it is I am getting camelCase propeperties.

It is not a big deal though.

As for passing the serializer, yes this a viable option and by the way I already noticed we can pass a serialier when I was getting an error when some of the payload fields were null (I think it was in iOS context) so I was trying to find a way to exclude properties with "null" values completely from serialization as FCM was reporting errors if I send an object that has a property value "null" so in that context I noticed we can pass a custom serializer...thus what I have on my mind is to create a wrapper or a proxy method/class to this library that would alway send payloads to FCM by using a custom serializer that has been setup so that it excludes from serialization propertis that have NULL values. I hope I am clear

co-dax avatar Mar 15 '23 17:03 co-dax

@co-dax thank you for your feedback! It all makes perfect sense! The serializer issues were somewhat expected by me because we switched from Newtonsoft to System.Text.Json, so yeah, null values :). And I only made it serialize using lower case. Expecting that some people might want to change serialization rules or go back to Newtonsoft, I added a way to switch the serializer. So it should be all covered. And yeah it's v4.x.x, it's supposed to break things lol. Anyways.. I'll keep this question open for a little to see if anyone else has something to say about the matter.

andrei-m-code avatar Mar 15 '23 17:03 andrei-m-code