public void when_doc_with_bool_false_with_serializer_default_value_handling_null_should_return_records() { var serializer = new JsonNetSerializer(); serializer.Customize(s => { s.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore; }); StoreOptions(x => x.Serializer(serializer)); // Note: with serializer settings DefaultValueHandling.Ignore, serialized JSON won't have Flag property var docWithFlagFalse = new TestClass(); theSession.Store(docWithFlagFalse); theSession.SaveChanges(); using (var s = theStore.OpenSession()) { var items = s.Query <TestClass>().Where(x => !x.Flag).ToList(); Assert.Single(items); Assert.Equal(docWithFlagFalse.Id, items[0].Id); } }
public static IServiceCollection ConfigureDocumentStore( this IServiceCollection services, IConfiguration configuration) { var serializer = new JsonNetSerializer(); serializer.Customize(c => c.ContractResolver = new ResolvePrivateSetters()); serializer.EnumStorage = EnumStorage.AsString; services.AddSingleton <IDocumentStore>(d => DocumentStore.For(_ => { _.Serializer(serializer); _.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate; _.DatabaseSchemaName = StoreOptions.DefaultDatabaseSchemaName; _.Connection(configuration.GetConnectionString("DefaultConnection")); _.Schema.For <Student>().DocumentAlias("Students"); _.Schema.For <Subject>().DocumentAlias("Subjects"); _.Schema.For <LectureTheatre>().DocumentAlias("LectureTheatres"); _.Schema.For <Enrollment>().DocumentAlias("Enrollments") .Index(table => table.StudentId) .Index(table => table.SubjectId) .Index(table => table.ApplicationId); })); return(services); }
public PostgresMartenDataStore( string connectionString, string keyMap, [Optional] IValidator <TKey, TValue> _validator = null) { var serializer = new JsonNetSerializer(); serializer.Customize(c => { c.TypeNameHandling = TypeNameHandling.None; }); _documentStore = DocumentStore.For(c => { c.Connection(connectionString); c.Schema.Include <MartenRegistry>(); c.Serializer(serializer); }); _keyMap = keyMap; this._validator = _validator; }
private static void SetStoreOptions(StoreOptions options, Config config, Action <StoreOptions>?configureOptions = null) { options.Connection(config.ConnectionString); options.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate; var schemaName = Environment.GetEnvironmentVariable("SchemaName"); options.Events.DatabaseSchemaName = schemaName ?? config.WriteModelSchema; options.DatabaseSchemaName = schemaName ?? config.ReadModelSchema; var serializer = new JsonNetSerializer { EnumStorage = EnumStorage.AsString }; serializer.Customize(s => { s.ContractResolver = new NonDefaultConstructorMartenJsonNetContractResolver( Casing.Default, CollectionStorage.Default, NonPublicMembersStorage.NonPublicSetters ); }); options.Serializer(serializer); configureOptions?.Invoke(options); }
private static JsonNetSerializer CustomizeJsonSerializer() { var serializer = new JsonNetSerializer(); serializer.Customize(_ => _.ContractResolver = new ProtectedSettersContractResolver()); return(serializer); }
private void ConfigureMarten(StoreOptions options, string connectionString) { options.Connection(connectionString); var jsonNetSerializer = new JsonNetSerializer(); jsonNetSerializer.Customize(serializer => serializer.UseCustomConverters()); options.Serializer(jsonNetSerializer); }
private static JsonNetSerializer CustomizeJsonSerializer() { var serializer = new JsonNetSerializer(); serializer.Customize(_ => { _.ContractResolver = new ProtectedSettersContractResolver(); _.Converters.Add(new StringEnumConverter()); }); return(serializer); }
private static JsonNetSerializer CustomizeJsonSerializer() { var serializer = new JsonNetSerializer(); serializer.Customize(_ => { _.ContractResolver = new ProtectedSettersContractResolver(); _.PreserveReferencesHandling = PreserveReferencesHandling.Objects; }); return(serializer); }
private static JsonNetSerializer GetCustomJsonSerializer() { var serializer = new JsonNetSerializer(); serializer .Customize(configuration => { configuration.ContractResolver = new PrivatePropertySetterResolver(); configuration.PreserveReferencesHandling = PreserveReferencesHandling.Objects; }); return(serializer); }
public CustomAggregatorLookupTests() { StoreOptions(options => { // SAMPLE: scenarios-immutableprojections-storesetup var serializer = new JsonNetSerializer(); serializer.Customize(c => c.ContractResolver = new ResolvePrivateSetters()); options.Serializer(serializer); options.Events.UseAggregatorLookup(AggregationLookupStrategy.UsePrivateApply); options.Events.InlineProjections.AggregateStreamsWith <AggregateWithPrivateEventApply>(); // ENDSAMPLE }); }
public void can_support_typenamehandling() { using (var store = SeparateStore(_ => { var serializer = new JsonNetSerializer(); serializer.Customize(config => { config.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects; }); _.Serializer(serializer); _.AutoCreateSchemaObjects = AutoCreate.All; _.UseJavascriptTransformsAndPatching(); })) { using (var session = store.OpenSession()) { var obj = new PatchTypeA { Id = "1", TypeB = new PatchTypeB { Name = "test" } }; session.Store(obj); session.SaveChanges(); } using (var session = store.OpenSession()) { var newObj = new PatchTypeB { Name = "test2" }; session.Patch <PatchTypeA>("1").Set(set => set.TypeB, newObj); session.SaveChanges(); } using (var session = store.OpenSession()) { var result = session.Json.FindById <PatchTypeA>("1"); var expected = "{\"Id\": \"1\", \"$type\": \"Marten.PLv8.Testing.Patching.PatchTypeA, Marten.PLv8.Testing\", \"TypeB\": {\"Name\": \"test2\", \"$type\": \"Marten.PLv8.Testing.Patching.PatchTypeB, Marten.PLv8.Testing\"}}"; Assert.Equal(expected, result); } } }
public MartenDatabaseFixture() { DocumentStore = DocumentStore .For(_ => { _.Connection("host=dev-machine;database=marten_ut_database;password=admin;username=postgres"); var serializer = new JsonNetSerializer(); var dcr = new DefaultContractResolver(); dcr.DefaultMembersSearchFlags |= BindingFlags.NonPublic; serializer.Customize(i => { i.ContractResolver = dcr; }); _.Serializer(serializer); }); }
public PostgresMartenDataStore( string connectionString, string keyMap, [Optional] IValidator <TKey, TValue> validator = null, [Optional] IReadOnlyList <IObserver <TKey, TValue> > typedObservers = null, [Optional] IReadOnlyList <IObserver> untypedObservers = null, [Optional] IReadOnlyList <IMutator <TKey, TValue> > typedMutators = null, [Optional] IReadOnlyList <IMutator> untypedMutators = null) { _connectionString = connectionString; var serializer = new JsonNetSerializer(); serializer.Customize(c => { c.TypeNameHandling = TypeNameHandling.None; }); _documentStore = DocumentStore.For(c => { c.Connection(_connectionString); c.Schema.Include <MartenRegistry>(); c.Serializer(serializer); }); _keyMap = keyMap; _validator = validator; _typedObservers = typedObservers ?? EmptyReadOnlyList <IObserver <TKey, TValue> > .Instance; _untypedObservers = untypedObservers ?? EmptyReadOnlyList <IObserver> .Instance; _typedMutators = typedMutators ?? EmptyReadOnlyList <IMutator <TKey, TValue> > .Instance; _untypedMutators = untypedMutators ?? EmptyReadOnlyList <IMutator> .Instance; }
public static IDocumentStore Create(IComponentContext componentContext) { return(DocumentStore .For(_ => { _.DatabaseSchemaName = "home_bills"; _.Connection("host=dev-machine;database=home_bills;password=admin;username=postgres"); var serializer = new JsonNetSerializer(); var dcr = new DefaultContractResolver(); dcr.DefaultMembersSearchFlags |= BindingFlags.NonPublic | BindingFlags.Instance; serializer.Customize(i => { i.ContractResolver = dcr; }); _.Serializer(serializer); })); }