Skip to content

Custom ContractJsonConverter is not working #1731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zabykrinich opened this issue Jan 18, 2016 · 1 comment
Closed

Custom ContractJsonConverter is not working #1731

zabykrinich opened this issue Jan 18, 2016 · 1 comment
Assignees

Comments

@zabykrinich
Copy link

I use alpha from master branch.

I Created JsonNetSerealizer with overrided protected override IList<Func<Type, JsonConverter>> ContractConverters => null;
But my ContractJsonConverter is not called.

I did some debugging and found that code in src\Nest\CommonAbstractions\SerializationBehavior\ElasticContractResolver.cs

 protected override JsonContract CreateContract(Type objectType)
{
    JsonContract contract = base.CreateContract(objectType);

    // this will only be called once and then cached

    if (typeof(IDictionary).IsAssignableFrom(objectType) && !typeof(IIsADictionary).IsAssignableFrom(objectType))
        contract.Converter = new VerbatimDictionaryKeysJsonConverter();
    else if (objectType == typeof(ServerError))
        contract.Converter = new ServerErrorJsonConverter();
    else if (objectType == typeof(DateTime) || objectType == typeof(DateTime?))
        contract.Converter = new IsoDateTimeConverter();
    else if (!objectType.FullName.StartsWith("Nest.", StringComparison.OrdinalIgnoreCase)) return contract;

    else if (ApplyExactContractJsonAttribute(objectType, contract)) return contract;
    else if (ApplyContractJsonAttribute(objectType, contract)) return contract;

    if (this._contractConverters.HasAny())
    {
        foreach (var c in this._contractConverters)
        {
            var converter = c(objectType);
            if (converter == null)
                continue;
            contract.Converter = converter;
            break;
        }
    }
    return contract;
}

Since my type name does not start from "Nest." it exits from function in case else if (!objectType.FullName.StartsWith("Nest.", StringComparison.OrdinalIgnoreCase)) return contract; . It does not check _contractConverters and uses the default one.

Can it be the bug?
Thank you a lot in advance!

@russcam
Copy link
Contributor

russcam commented Jan 25, 2016

Hey @zabykrinich, Thanks for reporting 👍 This does look like a bug

@russcam russcam added this to the 2.0.0 milestone Jan 25, 2016
@gmarz gmarz removed this from the 2.0.0 milestone Jan 25, 2016
@Mpdreamz Mpdreamz self-assigned this Jan 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants