Skip to content

Commit

Permalink
Merge pull request #1470 from preardon/feature/1457-RemoveNewtonsoft
Browse files Browse the repository at this point in the history
Replaced NewtonSoft.Json with System.Text.Json #1457
  • Loading branch information
iancooper authored Mar 29, 2021
2 parents 2829d95 + 4865b3d commit 99e554e
Show file tree
Hide file tree
Showing 115 changed files with 480 additions and 439 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Licence
#region Licence
/* The MIT License (MIT)
Copyright © 2014 Ian Cooper <[email protected]>
Expand All @@ -22,8 +22,8 @@ THE SOFTWARE. */

#endregion

using System.Text.Json;
using Greetings.Ports.Commands;
using Newtonsoft.Json;
using Paramore.Brighter;
using Paramore.Brighter.MessagingGateway.AWSSQS;

Expand All @@ -34,14 +34,14 @@ public class GreetingEventMessageMapper : IAmAMessageMapper<GreetingEvent>
public Message MapToMessage(GreetingEvent request)
{
var header = new MessageHeader(messageId: request.Id, topic: typeof(GreetingEvent).FullName.ToValidSNSTopicName(), messageType: MessageType.MT_EVENT);
var body = new MessageBody(JsonConvert.SerializeObject(request));
var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;
}

public GreetingEvent MapToRequest(Message message)
{
var greetingCommand = JsonConvert.DeserializeObject<GreetingEvent>(message.Body.Value);
var greetingCommand = JsonSerializer.Deserialize<GreetingEvent>(message.Body.Value, JsonSerialisationOptions.Options);

return greetingCommand;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Licence
#region Licence
/* The MIT License (MIT)
Copyright © 2014 Ian Cooper <[email protected]>
Expand All @@ -22,8 +22,8 @@ THE SOFTWARE. */

#endregion

using System.Text.Json;
using KafkaTaskQueueSamples.Greetings.Ports.Commands;
using Newtonsoft.Json;
using Paramore.Brighter;

namespace KafkaTaskQueueSamples.Greetings.Ports.Mappers
Expand All @@ -33,14 +33,14 @@ public class GreetingEventMessageMapper : IAmAMessageMapper<GreetingEvent>
public Message MapToMessage(GreetingEvent request)
{
var header = new MessageHeader(messageId: request.Id, topic: "greeting.event", messageType: MessageType.MT_EVENT);
var body = new MessageBody(JsonConvert.SerializeObject(request));
var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;
}

public GreetingEvent MapToRequest(Message message)
{
var greetingCommand = JsonConvert.DeserializeObject<GreetingEvent>(message.Body.Value);
var greetingCommand = JsonSerializer.Deserialize<GreetingEvent>(message.Body.Value, JsonSerialisationOptions.Options);

return greetingCommand;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Events.Ports.Commands;
using Newtonsoft.Json;
using System.Text.Json;
using Events.Ports.Commands;
using Paramore.Brighter;

namespace Events.Ports.Mappers
Expand All @@ -9,14 +9,14 @@ public class CompetingConsumerCommandMessageMapper : IAmAMessageMapper<Competing
public Message MapToMessage(CompetingConsumerCommand request)
{
var header = new MessageHeader(messageId: request.Id, topic: "multipleconsumer.command", messageType: MessageType.MT_COMMAND);
var body = new MessageBody(JsonConvert.SerializeObject(request));
var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;
}

public CompetingConsumerCommand MapToRequest(Message message)
{
var greetingCommand = JsonConvert.DeserializeObject<CompetingConsumerCommand>(message.Body.Value);
var greetingCommand = JsonSerializer.Deserialize<CompetingConsumerCommand>(message.Body.Value, JsonSerialisationOptions.Options);

return greetingCommand;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Licence
#region Licence
/* The MIT License (MIT)
Copyright © 2014 Ian Cooper <[email protected]>
Expand All @@ -22,8 +22,8 @@ THE SOFTWARE. */

#endregion

using System.Text.Json;
using Events.Ports.Commands;
using Newtonsoft.Json;
using Paramore.Brighter;

namespace Events.Ports.Mappers
Expand All @@ -33,14 +33,14 @@ public class GreetingEventMessageMapper : IAmAMessageMapper<GreetingEvent>
public Message MapToMessage(GreetingEvent request)
{
var header = new MessageHeader(messageId: request.Id, topic: "greeting.event", messageType: MessageType.MT_EVENT);
var body = new MessageBody(JsonConvert.SerializeObject(request));
var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;
}

public GreetingEvent MapToRequest(Message message)
{
var greetingCommand = JsonConvert.DeserializeObject<GreetingEvent>(message.Body.Value);
var greetingCommand = JsonSerializer.Deserialize<GreetingEvent>(message.Body.Value, JsonSerialisationOptions.Options);

return greetingCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ THE SOFTWARE. */
#endregion

using Greetings.Ports.Commands;
using Newtonsoft.Json;
using System.Text.Json;
using Paramore.Brighter;

namespace Greetings.Ports.Mappers
Expand All @@ -33,14 +33,14 @@ public class GreetingEventMessageMapper : IAmAMessageMapper<GreetingEvent>
public Message MapToMessage(GreetingEvent request)
{
var header = new MessageHeader(messageId: request.Id, topic: "greeting.event", messageType: MessageType.MT_EVENT);
var body = new MessageBody(JsonConvert.SerializeObject(request));
var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;
}

public GreetingEvent MapToRequest(Message message)
{
var greetingCommand = JsonConvert.DeserializeObject<GreetingEvent>(message.Body.Value);
var greetingCommand = JsonSerializer.Deserialize<GreetingEvent>(message.Body.Value, JsonSerialisationOptions.Options);

return greetingCommand;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Text.Json;
using Greetings.Ports.Commands;
using Newtonsoft.Json.Linq;
using Paramore.Brighter;

namespace Greetings.Ports.Mappers
Expand All @@ -15,8 +15,7 @@ public Message MapToMessage(GreetingReply request)
messageType: MessageType.MT_COMMAND,
correlationId: request.SendersAddress.CorrelationId);

var json = new JObject(new JProperty("Id", request.Id), new JProperty("Salutation", request.Salutation));
var body = new MessageBody(json.ToString());
var body = new MessageBody(JsonSerializer.Serialize(new GreetingsReplyBody(request.Id.ToString(), request.Salutation)));
var message = new Message(header, body);
return message;
}
Expand All @@ -25,9 +24,9 @@ public GreetingReply MapToRequest(Message message)
{
var replyAddress = new ReplyAddress(topic: message.Header.ReplyTo, correlationId: message.Header.CorrelationId);
var reply = new GreetingReply(replyAddress);
var body = JObject.Parse(message.Body.Value);
reply.Id = Guid.Parse((string)body["Id"]);
reply.Salutation = Convert.ToString(body["Salutation"]);
var body = JsonSerializer.Deserialize<GreetingsReplyBody>(message.Body.Value);
reply.Id = Guid.Parse(body.Id);
reply.Salutation = body.Salutation;

return reply;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Licence
#region Licence
/* The MIT License (MIT)
Copyright © 2014 Ian Cooper <[email protected]>
Expand All @@ -23,8 +23,8 @@ THE SOFTWARE. */
#endregion

using System;
using System.Text.Json;
using Greetings.Ports.Commands;
using Newtonsoft.Json.Linq;
using Paramore.Brighter;

namespace Greetings.Ports.Mappers
Expand All @@ -40,12 +40,7 @@ public Message MapToMessage(GreetingRequest request)
correlationId: request.ReplyAddress.CorrelationId,
replyTo: request.ReplyAddress.Topic);

var json = new JObject(
new JProperty("Id", request.Id),
new JProperty("Name", request.Name),
new JProperty("Language", request.Language)
);
var body = new MessageBody(json.ToString());
var body = new MessageBody(JsonSerializer.Serialize(new GreetingsRequestBody(request.Id.ToString(), request.Name, request.Language), JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;

Expand All @@ -55,9 +50,9 @@ public GreetingRequest MapToRequest(Message message)
{
var replyAddress = new ReplyAddress(topic: message.Header.ReplyTo, correlationId: message.Header.CorrelationId);
var command = new GreetingRequest(replyAddress);
var body = JObject.Parse(message.Body.Value);
command.Name = Convert.ToString(body["Name"]);
command.Language = Convert.ToString(body["Language"]);
var body = JsonSerializer.Deserialize<GreetingsRequestBody>(message.Body.Value, JsonSerialisationOptions.Options);
command.Name = body.Name;
command.Language = body.Language;
return command;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Greetings.Ports.Mappers
{
public class GreetingsReplyBody
{
public string Id { get; set; }
public string Salutation { get; set; }

public GreetingsReplyBody(string id, string salutation)
{
Id = id;
Salutation = salutation;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Greetings.Ports.Mappers
{
public class GreetingsRequestBody
{
public string Id { get; set; }
public string Name { get; set; }
public string Language { get; set; }

public GreetingsRequestBody (string id, string name, string language)
{
Id = id;
Name = name;
Language = language;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Licence
#region Licence
/* The MIT License (MIT)
Copyright © 2014 Ian Cooper <[email protected]>
Expand All @@ -22,8 +22,8 @@ THE SOFTWARE. */

#endregion

using System.Text.Json;
using Greetings.Ports.Commands;
using Newtonsoft.Json;
using Paramore.Brighter;

namespace Greetings.Ports.Mappers
Expand All @@ -33,14 +33,14 @@ public class GreetingEventMessageMapper : IAmAMessageMapper<GreetingEvent>
public Message MapToMessage(GreetingEvent request)
{
var header = new MessageHeader(messageId: request.Id, topic: "greeting.event", messageType: MessageType.MT_EVENT);
var body = new MessageBody(JsonConvert.SerializeObject(request));
var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;
}

public GreetingEvent MapToRequest(Message message)
{
var greetingCommand = JsonConvert.DeserializeObject<GreetingEvent>(message.Body.Value);
var greetingCommand = JsonSerializer.Deserialize<GreetingEvent>(message.Body.Value, JsonSerialisationOptions.Options);

return greetingCommand;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Licence
#region Licence
/* The MIT License (MIT)
Copyright © 2014 Ian Cooper <[email protected]>
Expand All @@ -22,8 +22,8 @@ THE SOFTWARE. */

#endregion

using System.Text.Json;
using Greetings.Ports.Events;
using Newtonsoft.Json;
using Paramore.Brighter;

namespace Greetings.Ports.Mappers
Expand All @@ -33,14 +33,14 @@ public class GreetingEventMessageMapper : IAmAMessageMapper<GreetingEvent>
public Message MapToMessage(GreetingEvent request)
{
var header = new MessageHeader(messageId: request.Id, topic: "greeting.event", messageType: MessageType.MT_EVENT);
var body = new MessageBody(JsonConvert.SerializeObject(request));
var body = new MessageBody(JsonSerializer.Serialize(request, JsonSerialisationOptions.Options));
var message = new Message(header, body);
return message;
}

public GreetingEvent MapToRequest(Message message)
{
var greetingCommand = JsonConvert.DeserializeObject<GreetingEvent>(message.Body.Value);
var greetingCommand = JsonSerializer.Deserialize<GreetingEvent>(message.Body.Value, JsonSerialisationOptions.Options);

return greetingCommand;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Paramore.Brighter.Inbox.DynamoDB/CommandItem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System;
using System.Text.Json;
using Amazon.DynamoDBv2.DataModel;
using Newtonsoft.Json;

namespace Paramore.Brighter.Inbox.DynamoDB
{
Expand Down Expand Up @@ -32,10 +32,10 @@ public CommandItem(T command, string contextKey)
Time = $"{TimeStamp.Ticks}";
CommandId = command.Id.ToString();
CommandType = typeof(T).Name;
CommandBody = JsonConvert.SerializeObject(command);
CommandBody = JsonSerializer.Serialize(command, JsonSerialisationOptions.Options);
ContextKey = contextKey;
}

public T ConvertToCommand() => JsonConvert.DeserializeObject<T>(CommandBody);
public T ConvertToCommand() => JsonSerializer.Deserialize<T>(CommandBody, JsonSerialisationOptions.Options);
}
}
6 changes: 3 additions & 3 deletions src/Paramore.Brighter.Inbox.MsSql/MsSqlInbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ THE SOFTWARE. */
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Paramore.Brighter.Inbox.Exceptions;
using Paramore.Brighter.Logging;

Expand Down Expand Up @@ -299,7 +299,7 @@ private DbCommand InitAddDbCommand(DbConnection connection, DbParameter[] parame

private DbParameter[] InitAddDbParameters<T>(T command, string contextKey) where T : class, IRequest
{
var commandJson = JsonConvert.SerializeObject(command);
var commandJson = JsonSerializer.Serialize(command, JsonSerialisationOptions.Options);
var parameters = new[]
{
CreateSqlParameter("CommandID", command.Id),
Expand All @@ -316,7 +316,7 @@ private TResult ReadCommand<TResult>(IDataReader dr, Guid commandId) where TResu
if (dr.Read())
{
var body = dr.GetString(dr.GetOrdinal("CommandBody"));
return JsonConvert.DeserializeObject<TResult>(body);
return JsonSerializer.Deserialize<TResult>(body, JsonSerialisationOptions.Options);
}

throw new RequestNotFoundException<TResult>(commandId);
Expand Down
3 changes: 0 additions & 3 deletions src/Paramore.Brighter.Inbox.MsSql/MsSqlInboxConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ THE SOFTWARE. */

#endregion

using System;
using Newtonsoft.Json;

namespace Paramore.Brighter.Inbox.MsSql
{
/// <summary>
Expand Down
Loading

0 comments on commit 99e554e

Please sign in to comment.