Skip to content

Commit

Permalink
Fixes to nullability in mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
craigedmunds committed Feb 11, 2025
1 parent 4c21a0a commit 4ecbd42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Btms.Backend.Cli/Features/GenerateModels/ClassMaps/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ public static void RegisterAlvsClassMaps()
{
GeneratorClassMap.RegisterClassMap("Header", map =>
{
map.MapProperty("ArrivalDateTime").IsDateTime().SetInternalName("ArrivesAt");
map.MapProperty("ArrivalDateTime")
.IsDateTime(DatetimeType.Epoch)
.SetInternalName("ArrivesAt");

map.MapProperty("MasterUCR").SetName("MasterUcr");
map.MapProperty("SubmitterTURN").SetName("SubmitterTurn");
map.MapProperty("DeclarationUCR").SetName("DeclarationUcr");
});

GeneratorClassMap.RegisterClassMap("Items", map =>
{
map.MapProperty("Documents");
map.MapProperty("Checks");
});

GeneratorClassMap.RegisterClassMap("Check", map =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace @ns

public static class @Model.GetClassName()Mapper
{
public static @Model.GetInternalFullClassName() Map(@Model.GetSourceFullClassName()? from)
public static @Model.GetInternalFullClassName() Map(@Model.GetSourceFullClassName() from)
{
if(from is null)
{
Expand All @@ -41,7 +41,7 @@ public static class @Model.GetClassName()Mapper
}
else
{
var line = $"to.{property.GetInternalPropertyName()} = {property.Mapper}.Map(from?.{@property.GetSourcePropertyName()});";
var line = $"to.{property.GetInternalPropertyName()} = {property.Mapper}.Map(from.{@property.GetSourcePropertyName()});";
<text>@line
</text>
}
Expand All @@ -54,22 +54,22 @@ public static class @Model.GetClassName()Mapper
{
if (property.IsArray)
{
var line = $"to.{property.GetInternalPropertyName()} = from?.{property.GetSourcePropertyName()}?.Select(x => {property.GetSourcePropertyTypeName()}Mapper.Map(x)).ToArray();";
var line = $"to.{property.GetInternalPropertyName()} = from.{property.GetSourcePropertyName()}?.Select(x => {property.GetSourcePropertyTypeName()}Mapper.Map(x)).ToArray();";
<text>@line
</text>

}
else
{
<text>to.@property.GetInternalPropertyName() = @property.GetSourcePropertyTypeName()Mapper.Map(from?.@property.GetSourcePropertyName());
<text>to.@property.GetInternalPropertyName() = @property.GetSourcePropertyTypeName()Mapper.Map(from.@property.GetSourcePropertyName());
</text>
}


}
else
{
<text>to.@property.GetInternalPropertyName() = from?.@property.GetSourcePropertyName();
<text>to.@property.GetInternalPropertyName() = from.@property.GetSourcePropertyName();
</text>
}
}
Expand Down
6 changes: 3 additions & 3 deletions Btms.SensitiveData/SensitiveDataSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Btms.SensitiveData;

public class SensitiveDataSerializer(IOptions<SensitiveDataOptions> options, ILogger<SensitiveDataSerializer> logger) : ISensitiveDataSerializer
{
private readonly JsonSerializerOptions jsonOptions = new()
private readonly JsonSerializerOptions _jsonOptions = new()
{
TypeInfoResolver = new SensitiveDataTypeInfoResolver(options.Value),
PropertyNameCaseInsensitive = true,
Expand All @@ -21,13 +21,13 @@ public class SensitiveDataSerializer(IOptions<SensitiveDataOptions> options, ILo

public T Deserialize<T>(string json, Action<JsonSerializerOptions>? optionsOverride = null)
{
var newOptions = jsonOptions;
var newOptions = _jsonOptions;
if (optionsOverride is not null)
{
newOptions = new JsonSerializerOptions
{
TypeInfoResolver = new SensitiveDataTypeInfoResolver(options.Value),
PropertyNameCaseInsensitive = true,
PropertyNameCaseInsensitive = false,
NumberHandling = JsonNumberHandling.AllowReadingFromString
};
optionsOverride(newOptions);
Expand Down

0 comments on commit 4ecbd42

Please sign in to comment.