Store XML or JSON as a "property" of a document

247 views
Skip to first unread message

Brent

unread,
Apr 23, 2012, 3:30:17 PM4/23/12
to rav...@googlegroups.com
Hello,

I'm capturing some data from an external system that is in XML format.  I've converted serialized that into a JSON object and extracted some properties for the core elements in my document, but want to keep a copy of the entire XML source in the document as well.

I read this thread: https://groups.google.com/d/topic/ravendb/b0vjBVOEFPc/discussion and I'm having the same issue as Maria stated:

Object serialized to String. RavenJObject instance expected.

So my question is, how can I set a property of a document to be a string of JSON?

e.g.

public class User
{
public string Name {get;set;}
public string SomeJson {get;set;}
}

//serialized XML into "SomeJson" using JSON.NET
...
...

session.store(new User { Name = "Bob", SomeJson = @"{"Name": "Bob", "EyeColor": "blue"}" })); 

Many thanks for any insight.  Love Raven so far!
 
 

Itamar Syn-Hershko

unread,
Apr 23, 2012, 4:15:53 PM4/23/12
to rav...@googlegroups.com
If storing that XML source is not going to be used during your normal operation, I'd consider saving it as an attachment. More so if the size is going to be larger than 1kb, which is most probably the case.

Brent

unread,
Apr 23, 2012, 4:50:54 PM4/23/12
to rav...@googlegroups.com
Thanks Itamar. Comments inline.

On Monday, April 23, 2012 4:15:53 PM UTC-4, Itamar Syn-Hershko wrote:
If storing that XML source is not going to be used during your normal operation, I'd consider saving it as an attachment. More so if the size is going to be larger than 1kb, which is most probably the case.

It's not that large and it does contain data that may be useful in the future, hence following Oren's guidance to serialize and store that JSON into an object property rather than an attachment. Any suggestions?

 

Itamar Syn-Hershko

unread,
Apr 23, 2012, 5:04:36 PM4/23/12
to rav...@googlegroups.com
"May be useful in the future" is not "going to be used during normal operation". It is there for you to fetch whenever needed, but if you are not going to take advantage of it during normal operation, why spend it within your Aggregate Root?

The problem with saving a string with a JSON object is that on the wire it becomes merged, and I'm not sure there is an easy way around that error.

Can you try this?

public class User
{
public string Name {get;set;}
public RavenJObject SomeJson {get;set;}
}

session.store(new User { Name = "Bob", SomeJson = RavenJObject.Parse(@"{"Name": "Bob", "EyeColor": "blue"}") }));

Brent

unread,
May 3, 2012, 7:21:14 PM5/3/12
to rav...@googlegroups.com
Thanks for the guidance.  I'll test this out and get back to you.
Reply all
Reply to author
Forward
0 new messages