Skip to content

Commit

Permalink
Fallback serializer for rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Nov 13, 2023
1 parent 138487b commit aa76b22
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli/Squidex.CLI/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<PackageTags>Squidex HeadlessCMS</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>11.2</Version>
<Version>11.3</Version>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,14 @@ public async Task StreamAllAsync(Func<TEntity, Task> callback, int skip = 0, Que
throw new SquidexException("Line does not start with data prefix.");
}

#pragma warning disable IDE0057 // Use range operator
var contentJson = line.Substring(Prefix.Length);
#pragma warning restore IDE0057 // Use range operator
var contentItem = contentJson.FromJson<TEntity>();
var stringReader = new StringReader(line);

for (var i = 0; i < Prefix.Length; i++)
{
stringReader.Read();
}

var contentItem = stringReader.FromJson<TEntity>();

await callback(contentItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public SquidexOptions UseFallbackSerializer()
{
SerializerSettings.Converters.Add(ListFallbackConverter.Clients);
SerializerSettings.Converters.Add(ListFallbackConverter.Languages);
SerializerSettings.Converters.Add(ListFallbackConverter.Rules);
SerializerSettings.Converters.Add(ListFallbackConverter.Schemas);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ public static T FromJson<T>(this string value)
return json;
}

/// <summary>
/// Read a value from a JSON string.
/// </summary>
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="value">The JSON string.</param>
/// <returns>
/// The deserialized value.
/// </returns>
public static T FromJson<T>(this StringReader value)
{
using var jsonReader = new JsonTextReader(value);

var jsonSerializer = JsonSerializer.CreateDefault(SerializerSettings);

return jsonSerializer.Deserialize<T>(jsonReader)!;
}

/// <summary>
/// Read a value from a JSON string and uses explicit type name handling.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ internal static class ListFallbackConverter
{
Items = items
});

public static readonly ListFallbackConverter<RulesDto, RuleDto> Rules =
new ListFallbackConverter<RulesDto, RuleDto>(
items => new RulesDto
{
Items = items
});
}

0 comments on commit aa76b22

Please sign in to comment.