ExpandableObjectConverter issue

328 views
Skip to first unread message

Alon Amsalem

unread,
Jun 30, 2013, 2:47:25 PM6/30/13
to rav...@googlegroups.com
Hello There,

I'm trying to store an object with attribute [TypeConverter(typeof(ExpandableObjectConverter))] and getting "Object serialized to String. RavenJObject instance expected." when saving changes.

Is there a way to keep the attribute and have RavenDB serialize the object normally?

thanks

Kijana Woodard

unread,
Jun 30, 2013, 3:41:45 PM6/30/13
to rav...@googlegroups.com

Is this json.net? If so, qualify the namespace.

--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alon Amsalem

unread,
Jul 1, 2013, 4:35:58 AM7/1/13
to rav...@googlegroups.com
It's not json.net

Oren Eini (Ayende Rahien)

unread,
Jul 1, 2013, 5:52:10 AM7/1/13
to rav...@googlegroups.com
Can you create a full failing test

Alon Amsalem

unread,
Jul 7, 2013, 11:19:20 AM7/7/13
to rav...@googlegroups.com
Failing Test

The following Console Application will fail at session.Store(test)

Error Message: Object serialized to String. RavenJObject instance expected.

Thank You


using System;
 
namespace ConsoleApplication1
{
    using System.ComponentModel;
 
    using Raven.Client.Document;
    using Raven.Client.Extensions;
 
    class Program
    {
        static void Main(string[] args)
        {
            var test = new Test { Name = "Hello World" };
 
            using (var documentStore = new DocumentStore { Url = "http://localhost:8080" }.Initialize())
            {
                documentStore.DatabaseCommands.EnsureDatabaseExists("MyDatabase");
 
                using (var session = documentStore.OpenSession("MyDatabase"))
                {
                    session.Store(test);
 
                    session.SaveChanges();
                }
            }
        }
    }
 
    [TypeConverter(typeof(ExpandableObjectConverter))] 
    public class Test
    {
        /// <summary>Gets or sets the Name.</summary>
        public string Name { getset; }
       
        /// <summary>The to string.</summary>
        /// <returns>The <see cref="string"/>Name.</returns>
        public override string ToString()
        {
            return this.Name;
        }
    }
}

Kijana Woodard

unread,
Jul 7, 2013, 11:27:32 AM7/7/13
to rav...@googlegroups.com

Why do you want to do this? What behavior are you trying to achieve?

--

Alon Amsalem

unread,
Jul 7, 2013, 11:39:07 AM7/7/13
to rav...@googlegroups.com
The attribute [TypeConverter(typeof(ExpandableObjectConverter))] enables the objects to be expandable in Property Grid.

Kijana Woodard

unread,
Jul 7, 2013, 11:41:39 AM7/7/13
to rav...@googlegroups.com

Oh. This has something to do with wpf. Ok. I had no idea.

Oren Eini (Ayende Rahien)

unread,
Jul 8, 2013, 1:40:43 AM7/8/13
to ravendb
Okay, I had a look at this, and the actual problem is that ExpandableObjectConverter is returning true to CanConvertTo(typeof(string))
At that point, we say, "Oh, this isn't an object, this is actually just a string", so we treat it as that.

To be more accurate, this isn't us doing that, it is JSON.Net.

You need to force it to be an object by specifying:

[Raven.Imports.Newtonsoft.Json.JsonObject]

Alon Amsalem

unread,
Jul 8, 2013, 3:37:06 AM7/8/13
to rav...@googlegroups.com
Thank you very much

you are the Best!
Reply all
Reply to author
Forward
0 new messages