review(Driver.OpcUaClient.Browser): add JsonStringEnumConverter (systemic enum bug)
Cross-module fix from the review sweep. -003 (Medium): the browser's JsonOpts lacked JsonStringEnumConverter (the factory+probe both carry it), so AdminUI string-enum configs (AuthType/SecurityPolicy/SecurityMode/TargetNamespaceKind) threw on deserialize. Added the converter (accepts string AND numeric) + TDD.
This commit is contained in:
+10
-1
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Opc.Ua;
|
||||
@@ -16,10 +17,18 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Browser;
|
||||
/// </summary>
|
||||
public sealed class OpcUaClientDriverBrowser : IDriverBrowser
|
||||
{
|
||||
// Kept identical to OpcUaClientDriverFactoryExtensions.JsonOptions and
|
||||
// OpcUaClientDriverProbe._opts so the browser parses a given DriverConfig JSON
|
||||
// the same way as the factory and the probe. The JsonStringEnumConverter lets
|
||||
// enum-valued knobs (SecurityPolicy / SecurityMode / AuthType / TargetNamespaceKind)
|
||||
// be authored as their string names — the natural form for AdminUI-emitted JSON.
|
||||
// JsonStringEnumConverter also accepts numeric ordinals, so existing numeric configs
|
||||
// continue to work without migration.
|
||||
private static readonly JsonSerializerOptions JsonOpts = new()
|
||||
{
|
||||
UnmappedMemberHandling = System.Text.Json.Serialization.JsonUnmappedMemberHandling.Skip,
|
||||
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter() },
|
||||
};
|
||||
|
||||
private readonly ILogger<OpcUaClientDriverBrowser> _logger;
|
||||
|
||||
Reference in New Issue
Block a user