Setting BSONNode value in MongoDB serialiser

Hi,

I’ve been using the MongoDB serialisation and it’s pretty neat being able to directly query my event store. However, I was getting NullPointerExceptions on command dispatch. This turned out to be due to the aggregateIdentifier in EventContainer being null, which in turn turned out to be due to the Mongo serialisation not handling the case where the value of a node is carried on the _value property of the DBObject.

I’ve created a commit here that fixes that specific problem, but as written it doesn’t process any other properties of the DBObject. That appears to work for my specific case but I’m not sure that it won’t cause unexpected side-effects. Should I add additional processing to set any attributes, etc?

Thanks,

Andy Duncan

Hi Andy,

that sounds like a nice little bug. If all the existing test cases keep running with your changes, you can be pretty confident that you don’t break anything. The “_value” attribute is used to simulate scenarios where the serialized XML format would contain attributes. If “_value” is the only child node, then the value of that node is added directly udner its parent.

So {root : {’_value’ : ‘someValue’} } becomes: {root : ‘someValue’}
But not {root : { ‘_value’ : ‘someValue’, ‘_otherAttr’ : ‘val’}}

Could you provide a pull request in github?
Cheers,

Allard

Hi Allard,

I was hoping that would be your answer. I’ve made a pull request for that change.

This was the specific problem I was having:

{
“eventContainer” : [
{
“events” : [ ]
},
{
“aggregateIdentifier” : [
{
“_value” : “298663550”
},
{
“attr_class” : “string”
}
]
},
{
“lastCommittedSequenceNumber” : “56”
}
]
},

When this was deserialised, aggregateIdentifier ended up null. I suppose it’s because the declaration of aggregateIdentifier is Object, so XStream records the actual class as an attribute. That does make me wonder if the code should take attributes into consideration. I always use strings for my aggregate identifiers so I don’t have anything handy to test it with.

Andy

Hi Andy,

I will have a look at your pull request shortly. The BSON serializer based on XStream does not produce the neatest JSON/BSON around, but it does seem to do the job for all sorts of objects. Unfortunately, XStream needs all sorts of meta-information to be able to deserialize objects again. And unfortunately, the order of nodes is important for XStream as well. That’s why there is always a List inside each node.

Cheers,

Allard