diff --git a/src/KubernetesClient.Models/KubernetesYaml.cs b/src/KubernetesClient.Models/KubernetesYaml.cs
index dd79e9d7..c677bcbf 100644
--- a/src/KubernetesClient.Models/KubernetesYaml.cs
+++ b/src/KubernetesClient.Models/KubernetesYaml.cs
@@ -15,16 +15,22 @@ namespace k8s
///
public static class KubernetesYaml
{
- private static readonly IDeserializer Deserializer =
+ private static readonly DeserializerBuilder CommonDeserializerBuilder =
new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithTypeConverter(new IntOrStringYamlConverter())
.WithTypeConverter(new ByteArrayStringYamlConverter())
.WithTypeConverter(new ResourceQuantityYamlConverter())
.WithAttemptingUnquotedStringTypeDeserialization()
- .WithOverridesFromJsonPropertyAttributes()
- .IgnoreUnmatchedProperties()
- .Build();
+ .WithOverridesFromJsonPropertyAttributes();
+ private static readonly IDeserializer StrictDeserializer =
+ CommonDeserializerBuilder
+ .Build();
+ private static readonly IDeserializer Deserializer =
+ CommonDeserializerBuilder
+ .IgnoreUnmatchedProperties()
+ .Build();
+ private static IDeserializer GetDeserializer(bool strict) => strict ? StrictDeserializer : Deserializer;
private static readonly IValueSerializer Serializer =
new SerializerBuilder()
@@ -100,8 +106,9 @@ public void WriteYaml(IEmitter emitter, object value, Type type)
/// A map from apiVersion/kind to Type. For example "v1/Pod" -> typeof(V1Pod). If null, a default mapping will
/// be used.
///
+ /// true if a strict deserializer should be used (throwing exception on unknown properties), false otherwise
/// collection of objects
- public static async Task> LoadAllFromStreamAsync(Stream stream, IDictionary typeMap = null)
+ public static async Task> LoadAllFromStreamAsync(Stream stream, IDictionary typeMap = null, bool strict = false)
{
var reader = new StreamReader(stream);
var content = await reader.ReadToEndAsync().ConfigureAwait(false);
@@ -117,8 +124,9 @@ public static async Task> LoadAllFromStreamAsync(Stream stream, IDi
/// A map from apiVersion/kind to Type. For example "v1/Pod" -> typeof(V1Pod). If null, a default mapping will
/// be used.
///
+ /// true if a strict deserializer should be used (throwing exception on unknown properties), false otherwise
/// collection of objects
- public static async Task> LoadAllFromFileAsync(string fileName, IDictionary typeMap = null)
+ public static async Task> LoadAllFromFileAsync(string fileName, IDictionary typeMap = null, bool strict = false)
{
using (var fileStream = File.OpenRead(fileName))
{
@@ -136,8 +144,9 @@ public static async Task> LoadAllFromFileAsync(string fileName, IDi
/// A map from apiVersion/kind to Type. For example "v1/Pod" -> typeof(V1Pod). If null, a default mapping will
/// be used.
///
+ /// true if a strict deserializer should be used (throwing exception on unknown properties), false otherwise
/// collection of objects
- public static List