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

Use Default Newtonsoft serializer settings for deserializing WebsocketMessageWrapper #661

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public byte[] SerializeToBytes(GraphQLWebSocketRequest request)
return Encoding.UTF8.GetBytes(json);
}

public Task<WebsocketMessageWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream) => DeserializeFromUtf8Stream<WebsocketMessageWrapper>(stream);
public Task<WebsocketMessageWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream) => DeserializeFromUtf8Stream<WebsocketMessageWrapper>(stream, DefaultJsonSerializerSettings);

public GraphQLWebSocketResponse<TResponse> DeserializeToWebsocketResponse<TResponse>(byte[] bytes) =>
JsonConvert.DeserializeObject<GraphQLWebSocketResponse<TResponse>>(Encoding.UTF8.GetString(bytes),
JsonSerializerSettings);

public Task<GraphQLResponse<TResponse>> DeserializeFromUtf8StreamAsync<TResponse>(Stream stream, CancellationToken cancellationToken) => DeserializeFromUtf8Stream<GraphQLResponse<TResponse>>(stream);
public Task<GraphQLResponse<TResponse>> DeserializeFromUtf8StreamAsync<TResponse>(Stream stream, CancellationToken cancellationToken) => DeserializeFromUtf8Stream<GraphQLResponse<TResponse>>(stream, JsonSerializerSettings);

private Task<T> DeserializeFromUtf8Stream<T>(Stream stream)
private static Task<T> DeserializeFromUtf8Stream<T>(Stream stream, JsonSerializerSettings jsonSerializerSettings)
{
using var sr = new StreamReader(stream);
using JsonReader reader = new JsonTextReader(sr);
var serializer = JsonSerializer.Create(JsonSerializerSettings);
var serializer = JsonSerializer.Create(jsonSerializerSettings);
return Task.FromResult(serializer.Deserialize<T>(reader));
}
}