本文介绍了如何为Akavache设置JsonSerializerSettings?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经像这样设置了JSON.NET的全局转换器默认值:

I have set the global converter defaults for JSON.NET like so:

        var jsonSerializerSettings = new JsonSerializerSettings
        {
            Converters = new JsonConverter[] { new QuestionTypeConverter() }
        };
        JsonConvert.DefaultSettings = () => jsonSerializerSettings;

这与我的其余代码("QuestionTypeConverter"正在使用并按预期工作)一起很好地工作,但是,当从Akavache缓存中检索对象时,我的"QuestionTypeConverter"将被忽略,因此我的对象不会被反序列化适当地.如何通过Akavache强制使用自定义类型转换器,或者如何让Akavache使用JSON.NET的默认设置?

This works well with the rest of my code ("QuestionTypeConverter" is being used and works as expected), however, when retrieving an object from the Akavache cache, my "QuestionTypeConverter" is ignored and thus my object does not get deserialized properly.How can I enforce the usage of my custom type converters with Akavache or have Akavache use the default settings of JSON.NET?

推荐答案

调用Splat.Locator.CurrentMutable.RegisterConstant(mySettings, typeof(JsonSerializerSettings))覆盖Akavache的序列化程序设置

Call Splat.Locator.CurrentMutable.RegisterConstant(mySettings, typeof(JsonSerializerSettings)) to override the serializer settings for Akavache

这篇关于如何为Akavache设置JsonSerializerSettings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:08