Skip to content

Flag cannot be deserialised if using "hide sensitive data" + non-Edge API #128

@rolodato

Description

@rolodato
using Flagsmith;

var flagsmithClient = new FlagsmithClient("ser...", "https://example.flagsmith.com/api/v1/");
var flags = await flagsmithClient.GetEnvironmentFlags();
Console.WriteLine(flags.AllFlags());

If the target environment has "Hide sensitive data" enabled, this fails with:

Details
Unhandled exception. Newtonsoft.Json.JsonSerializationException: Error converting value {null} to type 'System.Int32'. Path '[0].id', line 1, position 11.
 ---> System.InvalidCastException: Null object cannot be converted to a value type.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   --- End of inner exception stack trace ---
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at Flagsmith.FlagsmithClient.GetFeatureFlagsFromApi()
   at Flagsmith.FlagsmithClient.GetFeatureFlagsFromCorrectSource()
   at Flagsmith.FlagsmithClient.GetEnvironmentFlags()
   at Program.<Main>$(String[] args) in /Users/rolodato/source/flagsmith/FlagsmithExample/FlagsmithExample/Program.cs:line 6
   at Program.<Main>(String[] args)

Process finished with exit code 134.

This does not happen with the Edge API - compare these responses:

% curl 'https://edge.api.flagsmith.com/api/v1/flags/' -H 'x-environment-key: PPaxBNpveqUsX27RKtNaps'
[{"feature": {"id": 118078, "name": "my_feat", "type": "STANDARD"}, "enabled": false, "feature_state_value": null}
% curl 'https://api.flagsmith.com/api/v1/flags/' -H 'x-environment-key: PPaxBNpveqUsX27RKtNaps'
[{"id":null,"feature":{"id":118078,"name":"my_feat","created_date":null,"description":null,"initial_value":null,"default_enabled":null,"type":"STANDARD"},"feature_state_value":null,"environment":null,"identity":null,"feature_segment":null,"enabled":false}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions