Giter Club home page Giter Club logo

Comments (5)

daveleek avatar daveleek commented on June 16, 2024 1

Thank you @erandjo for raising this. We'll have a look! Interesting though, I'd have thought providing Naming policy camel case through JsonSerializerOptions would have sorted this

from unleash-client-dotnet.

daveleek avatar daveleek commented on June 16, 2024 1

where I found that dependencies was optional and defaulting to an empty lists of dependencies (similar to the issue you shared). Is this the reason why dependent features wont work when using System.Text.Json, and will this also be true for variants?

Hello @erandjo! No, it's inside dependency implementation. Spec requires enabled to default to true if not set in the JSON payload, and we didn't want to expose a nullable boolean on the dependency itself, leading to System.Text.Json not being able to resolve the type/property/parameter since once is a bool? and the other a regular bool. Ends up with runtime deserialization errors. (dotnet/runtime#44428)

Docs on dependent features is here by the way: https://docs.getunleash.io/reference/dependent-features

from unleash-client-dotnet.

sjaanus avatar sjaanus commented on June 16, 2024

Couple of things here

  1. For serialization use also camel case options
  2. Setting stream position to 0 in the end of serialization

Although, this will eventually not work with Dependent Features, because of an issue in .NET runtime dotnet/runtime#44428

class TextJsonSerializer : IJsonSerializer
{
    private readonly JsonSerializerOptions options;

    public TextJsonSerializer()
    {
        options = new JsonSerializerOptions
        {
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        };
    }

    T IJsonSerializer.Deserialize<T>(Stream stream)
    {
        var instance = JsonSerializer.Deserialize<T>(stream, options);
        if (instance == null)
        {
            throw new Exception("The result of serializing feature toggle is null");
        }
        return instance;
    }

    void IJsonSerializer.Serialize<T>(Stream stream, T instance)
    {
        JsonSerializer.Serialize(stream, instance, options);
        stream.Position  = 0;
    }
}

from unleash-client-dotnet.

erandjo avatar erandjo commented on June 16, 2024

Wow. thank you. This seems to be a blunder on my part, forgetting to pass in options; I am sorry about that. I will close the the issue. Interesting side note about dependent features. Thanks again.

from unleash-client-dotnet.

erandjo avatar erandjo commented on June 16, 2024

I searched for dependent features on unleash and unleash dotnet sdk out of curiosity for what you meant with the comment about dependent features not working in the future. I couldnt find an exact reference to dependent features (with exception of some tests).

These tests lead me to the FeatureToggle constructor:

        public FeatureToggle(string name, string type, bool enabled, bool impressionData, List<ActivationStrategy> strategies, List<VariantDefinition> variants = null, List<Dependency> dependencies = null)
        {
            Name = name;
            Type = type;
            Enabled = enabled;
            ImpressionData = impressionData;
            Strategies = strategies ?? new List<ActivationStrategy>();
            Variants = variants ?? new List<VariantDefinition>();
            Dependencies = dependencies ?? new List<Dependency>();
        }

where I found that dependencies was optional and defaulting to an empty lists of dependencies (similar to the issue you shared). Is this the reason why dependent features wont work when using System.Text.Json, and will this also be true for variants?

from unleash-client-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.