XStream BSON serialization

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

XStream BSON serialization

Xybrek
Hello,

Anyone knows of a library or extension to XStream that allows
(de)serialization of BSON documents?

This is the only implementation I can find so far:
http://www.axonframework.org/apidocs/2.0/org/axonframework/serializer/bson/DBObjectXStreamSerializer.html

However, the framework's serializer is quite geared toward its
frameworks models etc. Thus, very hard to integrate with a simple library.

Is there any library that is independent of a framework.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream BSON serialization

Paul Hammant-3
Can you do test-driven-development ?  You could make the same thing and donate it to the XStream project.  I started the JSON driver and contributed it with tests (though it required some more work).

-ph

On Sat, Apr 20, 2013 at 1:59 AM, Xybrek <[hidden email]> wrote:
Hello,

Anyone knows of a library or extension to XStream that allows (de)serialization of BSON documents?

This is the only implementation I can find so far:
http://www.axonframework.org/apidocs/2.0/org/axonframework/serializer/bson/DBObjectXStreamSerializer.html

However, the framework's serializer is quite geared toward its frameworks models etc. Thus, very hard to integrate with a simple library.

Is there any library that is independent of a framework.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: XStream BSON serialization

Xybrek
On 04/20/2013 04:13 PM, Paul Hammant wrote:

> Can you do test-driven-development ?  You could make the same thing and
> donate it to the XStream project.  I started the JSON driver and
> contributed it with tests (though it required some more work).
>
> -ph
>
> On Sat, Apr 20, 2013 at 1:59 AM, Xybrek
> <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hello,
>
>     Anyone knows of a library or extension to XStream that allows
>     (de)serialization of BSON documents?
>
>     This is the only implementation I can find so far:
>     http://www.axonframework.org/__apidocs/2.0/org/axonframework/__serializer/bson/__DBObjectXStreamSerializer.html
>     <http://www.axonframework.org/apidocs/2.0/org/axonframework/serializer/bson/DBObjectXStreamSerializer.html>
>
>     However, the framework's serializer is quite geared toward its
>     frameworks models etc. Thus, very hard to integrate with a simple
>     library.
>
>     Is there any library that is independent of a framework.
>
>
>     ------------------------------__------------------------------__---------
>     To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/__manage_email
>     <http://xircles.codehaus.org/manage_email>
>
>
>

Paul, I'm still having problem extracting and making the
DBObjectXStreamSerializer from the link I posted. I hope I can help like
you.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream BSON serialization

Jörg Schaible-2
In reply to this post by Xybrek
Hi,

Xybrek wrote:

> Hello,
>
> Anyone knows of a library or extension to XStream that allows
> (de)serialization of BSON documents?
>
> This is the only implementation I can find so far:
>
http://www.axonframework.org/apidocs/2.0/org/axonframework/serializer/bson/DBObjectXStreamSerializer.html
>
> However, the framework's serializer is quite geared toward its
> frameworks models etc. Thus, very hard to integrate with a simple library.
>
> Is there any library that is independent of a framework.

Actually I think that BSON and XStream do not really match. See, XStream's
converters will typically produce Strings i.e. all converters are
implemented to work with String representations of the objects they handle.
The hierarchical writer will write all values as String into the resulting
document - there's nothing else possible.

Actually even XStream's "binary" driver will simply write optimized values
as Strings and I don't see, how you can write anything that will produce a
compliant BSON document.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream BSON serialization

Xybrek
On 04/20/2013 11:14 PM, Jörg Schaible wrote:

> Hi,
>
> Xybrek wrote:
>
>> Hello,
>>
>> Anyone knows of a library or extension to XStream that allows
>> (de)serialization of BSON documents?
>>
>> This is the only implementation I can find so far:
>>
> http://www.axonframework.org/apidocs/2.0/org/axonframework/serializer/bson/DBObjectXStreamSerializer.html
>>
>> However, the framework's serializer is quite geared toward its
>> frameworks models etc. Thus, very hard to integrate with a simple library.
>>
>> Is there any library that is independent of a framework.
>
> Actually I think that BSON and XStream do not really match. See, XStream's
> converters will typically produce Strings i.e. all converters are
> implemented to work with String representations of the objects they handle.
> The hierarchical writer will write all values as String into the resulting
> document - there's nothing else possible.
>
> Actually even XStream's "binary" driver will simply write optimized values
> as Strings and I don't see, how you can write anything that will produce a
> compliant BSON document.
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>
>

I see, I just wonder how the Axon Framework was able to achieve this.
This is one of the unit test code I found for the DBObjectXStreamSerializer:

        @Test
     public void testSerializeAndDeserializeDomainEvent() {
         SerializedObject<byte[]> serializedEvent =
testSubject.serialize(new TestEvent("Henk"), byte[].class);
         assertNotNull(serializedEvent.getData());
         Object actualResult = testSubject.deserialize(serializedEvent);
         assertTrue(actualResult instanceof TestEvent);
         TestEvent actualEvent = (TestEvent) actualResult;
         assertEquals("Henk", actualEvent.getName());
     }


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream BSON serialization

Jörg Schaible-2
Hi,

> I see, I just wonder how the Axon Framework was able to achieve this.
> This is one of the unit test code I found for the
> DBObjectXStreamSerializer:
>
> @Test
>      public void testSerializeAndDeserializeDomainEvent() {
>          SerializedObject<byte[]> serializedEvent =
> testSubject.serialize(new TestEvent("Henk"), byte[].class);
>          assertNotNull(serializedEvent.getData());
>          Object actualResult = testSubject.deserialize(serializedEvent);
>          assertTrue(actualResult instanceof TestEvent);
>          TestEvent actualEvent = (TestEvent) actualResult;
>          assertEquals("Henk", actualEvent.getName());
>      }

Well, when you look in to the JSONWriter implementation, you'll see that the
writer gets the information, that the provided String value was e.g.
originally an integer. However, this is required, since these values are
written in a different format in JSON. Nobody stops you from converting this
String into an integer again, get a native interface for an underlying BSON
writer and do what you have to do. But I doubt that you will get anything
efficient.

- Jörg




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email