Example #1
0
        /// <summary>
        /// Serialize the given object resolving any properties which are <see cref="DatabaseEntity"/> into pointers using <see cref="DatabaseEntityJsonConverter"/>
        /// </summary>
        /// <param name="value"></param>
        /// <param name="repositoryLocator"></param>
        /// <returns></returns>
        public static string SerializeObject(object value, IRDMPPlatformRepositoryServiceLocator repositoryLocator)
        {
            var databaseEntityJsonConverter = new DatabaseEntityJsonConverter(repositoryLocator);

            var settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.None,
                TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
                Converters       = new JsonConverter[] { databaseEntityJsonConverter },
                ContractResolver = new DictionaryAsArrayResolver()
            };

            return(JsonConvert.SerializeObject(value, settings));
        }
Example #2
0
        /// <summary>
        /// Deserializes a string created with <see cref="SerializeObject(object,IRDMPPlatformRepositoryServiceLocator)"/>.  This involves two additional areas of functionality
        /// beyond basic JSON:
        ///
        /// <para>1. Any database pointer (e.g. Catalogue 123 0xab1d) will be fetched and returned from the appropriate platform database (referenced by <paramref name="repositoryLocator"/>)</para>
        /// <para>2. Objects do not need a default constructor, instead <see cref="PickAnyConstructorJsonConverter"/> will be used with <paramref name="objectsForConstructingStuffWith"/></para>
        /// <para>3. Any objects implementing <see cref="IPickAnyConstructorFinishedCallback"/> will have <see cref="IPickAnyConstructorFinishedCallback.AfterConstruction"/> called</para>
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <param name="repositoryLocator"></param>
        /// <param name="objectsForConstructingStuffWith"></param>
        /// <returns></returns>
        public static object DeserializeObject(string value, Type type, IRDMPPlatformRepositoryServiceLocator repositoryLocator, params object[] objectsForConstructingStuffWith)
        {
            var databaseEntityJsonConverter = new DatabaseEntityJsonConverter(repositoryLocator);
            var lazyJsonConverter           = new PickAnyConstructorJsonConverter(new[] { repositoryLocator }.Union(objectsForConstructingStuffWith).ToArray());

            var settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.None,
                TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
                Converters       = new JsonConverter[] { databaseEntityJsonConverter, lazyJsonConverter },
                ContractResolver = new DictionaryAsArrayResolver()
            };

            return(JsonConvert.DeserializeObject(value, type, settings));
        }