-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy pathFhirClientSerializationEngineExtensions.cs
122 lines (107 loc) · 5.24 KB
/
FhirClientSerializationEngineExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#nullable enable
/*
* Copyright (c) 2023, Firely ([email protected]) and contributors
* See the file CONTRIBUTORS for details.
*
* This file is licensed under the BSD 3-Clause license
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE
*/
using Hl7.Fhir.Serialization;
namespace Hl7.Fhir.Rest
{
/// <summary>
/// A set of extension methods to configure the serialization/deserialization engine used by the client to some common defaults.
/// </summary>
public static class FhirClientSerializationEngineExtensions
{
/// <summary>
/// Configures the FhirClient to use the legacy serialization behaviour, using the <see cref="FhirClientSettings.ParserSettings"/>.
/// </summary>
public static BaseFhirClient WithLegacySerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine =
FhirSerializationEngineFactory.Legacy.FromParserSettings(client.Inspector,
#pragma warning disable CS0618 // Type or member is obsolete
client.Settings.ParserSettings);
#pragma warning restore CS0618 // Type or member is obsolete
return client;
}
/// <summary>
/// Configures the FhirClient to use the newer POCO-based serializer, configured to parse the incoming data strictly.
/// </summary>
public static BaseFhirClient WithStrictSerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Strict(client.Inspector);
return client;
}
/// <summary>
/// Configures the FhirClient to use the legacy serializer, configured to parse the incoming data strictly.
/// </summary>
public static BaseFhirClient WithStrictLegacySerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Legacy.Strict(client.Inspector);
return client;
}
/// <summary>
/// Configures the FhirClient to use the newer POCO-based serializer, configured to ignore recoverable errors in the
/// the incoming data.
/// </summary>
public static BaseFhirClient WithLenientSerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Recoverable(client.Inspector);
return client;
}
/// <summary>
/// Configures the FhirClient to use the legacy serializer, configured to be permissive.
/// </summary>
public static BaseFhirClient WithPermissiveLegacySerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Legacy.Permissive(client.Inspector);
return client;
}
/// <summary>
/// Configures the FhirClient to use the newer POCO-based serializer, configured to ignore errors that can
/// be caused when encountering data from a newer version of FHIR. NB: This may cause data loss.
/// </summary>
public static BaseFhirClient WithBackwardsCompatibleSerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.BackwardsCompatible(client.Inspector);
return client;
}
/// <summary>
/// Configures the FhirClient to use the legacy serializer, configured to ignore errors that can
/// be caused when encountering data from a newer version of FHIR. NB: This may cause data loss.
/// </summary>
public static BaseFhirClient WithBackwardsCompatibleLegacySerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Legacy.BackwardsCompatible(client.Inspector);
return client;
}
/// <summary>
/// Configures the FhirClient to use the newer POCO-based serializer, configured to ignore all errors.
/// NB: This may cause data loss.
/// </summary>
public static BaseFhirClient WithOstrichModeSerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Ostrich(client.Inspector);
return client;
}
public static BaseFhirClient WithCustomIgnoreListSerializer(this BaseFhirClient client, string[] ignoreList)
{
var xmlSettings = new ParserSettings().Ignoring(ignoreList);
var jsonSettings = (FhirJsonConverterOptions)new FhirJsonConverterOptions().Ignoring(ignoreList);
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Custom(client.Inspector, jsonSettings, xmlSettings);
return client;
}
/// <summary>
/// Configures the FhirClient to use the legacy serializer, configured to ignore all errors.
/// NB: This may cause data loss.
/// </summary>
public static BaseFhirClient WithOstrichModeLegacySerializer(this BaseFhirClient client)
{
client.Settings.SerializationEngine = FhirSerializationEngineFactory.Legacy.Ostrich(client.Inspector);
return client;
}
}
}
#nullable restore