public void ListOnDynamicJsonObjectFromJsonWillFailToBeAJsonList() { var conventions = new DocumentConvention(); var jObject = RavenJObject.FromObject(page, conventions.CreateSerializer()); dynamic dynamicObject = new DynamicJsonObject(jObject); Assert.NotNull(dynamicObject.CoAuthors as IEnumerable); Assert.NotNull(dynamicObject.CoAuthors.Length); Assert.Equal(2, dynamicObject.CoAuthors.Length); }
public object EntityFromJsonStream(Type type, BlittableJsonReaderObject jsonObject) { if (_reader == null) { _reader = new BlittableJsonReader(); } if (_serializer == null) { _serializer = _conventions.CreateSerializer(); } _reader.Init(jsonObject); return(_serializer.Deserialize(_reader, type)); }
public void CanSerializeYieldGetterMethods() { // If this test breaks, this is likely becaused we merged // a new version of JSON.Net, which can revert a modification that we made to the code // Look at the other changes that happened in this commit (see the git log for that) // And at any rate, the full explanation, including the full reasoning is here: // http://issues.hibernatingrhinos.com/issue/RavenDB-3931 // // Don't try to fix this issue without reading the details, it is a single line fix, but it // takes time to get to the right reason var documentConvention = new DocumentConvention(); var jsonSerializer = documentConvention.CreateSerializer(); var stringWriter = new StringWriter(); jsonSerializer.Serialize(stringWriter, new Item()); var str = stringWriter.GetStringBuilder().ToString(); jsonSerializer.Deserialize<Item>(new JsonTextReader(new StringReader(str))); }
public void LinqQueryWithStaticCallOnEnumerableIsCanBeCompiledAndRun() { var indexDefinition = new IndexDefinitionBuilder<Page> { Map = pages => from p in pages from coAuthor in p.CoAuthors.DefaultIfEmpty() select new { p.Id, CoAuthorUserID = coAuthor != null ? coAuthor.UserId : -1 } }.ToIndexDefinition(new DocumentConvention()); var mapInstance = new DynamicViewCompiler("testView", indexDefinition, "."). GenerateInstance(); var conventions = new DocumentConvention(); var o = RavenJObject.FromObject(page,conventions.CreateSerializer()); o["@metadata"] = new RavenJObject {{"Raven-Entity-Name", "Pages"}}; dynamic dynamicObject = new DynamicJsonObject(o); var result = mapInstance.MapDefinitions[0](new[] { dynamicObject }).ToList<object>(); Assert.Equal("{ Id = 0, CoAuthorUserID = 1, __document_id = }", result[0].ToString()); Assert.Equal("{ Id = 0, CoAuthorUserID = 2, __document_id = }", result[1].ToString()); }