-
Notifications
You must be signed in to change notification settings - Fork 22
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
JSON Encoding issues #1255
Comments
➤ Automation for Jira commented: The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3809 |
@fdmarc sure we will most likely update the docs 👍 . Thanks for noticing : ) |
I have a bit more information to help debug this. Here is a minimal repro from our codebase with the error message: static class AblyExtensions
{
public static Task<HttpPaginatedResponse> PublishAsync(this AblyRest ably)
{
var batch = JToken.Parse("{}");
return ably.Request("POST", "/messages", null, batch, null);
}
} Produces this error:
|
@fdmarc got it 👍 . |
That's not an option unfortunately - there is no |
Understood. Your requirement is publishing multiple messages on multiple channels at the same time, right? |
My immediate need is to send the same message to roughly 1-5 connected clients. This is how I was approaching it: static class AblyExtensions
{
public static Task<HttpPaginatedResponse> PublishAsync(this AblyRest ably, IEnumerable<string> channels, IEnumerable<Message> messages)
{
JObject batch = new() {
{ "channels", new JObject(channels) },
{ "messages", new JObject(messages) }
};
return ably.Request("POST", "/messages", null, batch, null);
}
} |
For the time being, you can do
|
Yup, but I'm making the HTTP calls in in parallel: var message = new Message
{
Id = eventBase.FlipdishEventId.ToString(),
Name = eventBase.EventName,
Data = JsonConvert.SerializeObject(eventBase.GenericMapToPublicModel()),
Encoding = "json",
};
// TODO:
// https://github.com/ably/ably-dotnet/issues/1151
// The Ably C# SDK does not support batch sending at present.
var tasks = channels.Select(channel =>
_restClient.Channels.Get(channel).PublishAsync(message));
await Task.WhenAll(tasks); |
I don't see it as a problem as long as the number of channels are limited ( ~10/12 channels). |
However, this should be a small change to be made from our side to the |
Could you add an |
It's not a part of standard ably public API specification : ( |
@fdmarc we have created a new release for this. Please use |
I've had two problems encoding C# objects into JSON with the Ably SDK.
First, when trying to encode a
TokenRequest
fromIRestClient.Auth.CreateTokenRequestObjectAsync
, by calling JSON.net in my HTTP controller. The call toJsonConvert.SerializeObject(tokenRequest)
was returning JSON with the original field names from theTokenRequest
class, and ignoring theJsonProperty
attributes. So the resulting JSON had field namesKeyName
,Ttl
rather thankeyName
,ttl
, etc.The issue seemed to be that version of JSON.net in my app was not able to understand the
JsonProperty
attributes from your SDK.I solved this problem by calling the (deprecated)
CreateTokenRequestAsync
function, which returned the correct JSON (I can only guess as to who this worked).The second issue that I hit was converting the other way - I was trying to send domain objects from my app as the payload of Ably messages. This time my
JsonProperty
attributes were being ignored. I solved this problem using this trick:#92 (comment)
Do you have thoughts on how to address these problems?
If not, it would be nice to include this code snippet in the docs, since it's very powerful when you want to have fine-grained control over the JSON.
Thanks
The text was updated successfully, but these errors were encountered: