Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Why .NET byte[] array becomes java.beans.XMLDecoder?

I am trying to store a byte array in binary form as follows but it seems like the data becomes an XML string in the space.

I have an interface "IMyType" with a member defined like this:

private byte[] _payload;
public byte[] Payload
{
get
{
return _payload;
}
set
{
_payload = value;
}
}

I then update/write the node as follows:
n.Payload = new byte[] { 1, 2, 3 };
Update(n);
public void Update(IMyType obj)
{
_proxy.Update(obj);
}

The object is stored properly, but when I open the Payload field in the Management Center after making a Query on the object list and selecting the Payload field on an entry, it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_16" class="java.beans.XMLDecoder">
<array class="byte" length="3">
<void index="0">
<byte>1</byte>
</void>
<void index="1">
<byte>2</byte>
</void>
<void index="2">
<byte>3</byte>
</void>
</array>

How come the type becomes stored as an XML string? (It should be just three bytes). Any way to control this through attributes or similar?

I'm using XAP.NET 7.0.0 M8.

Advice appreciated. h4. Attachments

[Screenshot_Object_Query_Result_Table_View.gif|/upfiles/13759708809437141.gif]

[Screenshot_Binary_View_of_Payload_Field.gif|/upfiles/1375970880207641.gif]

[Screenshot_Space_Schema_Of_Payload_Class.gif|/upfiles/13759708809701041.gif]

[Screenshot_XML_View_of_Payload_Field.gif|/upfiles/13759708809923541.gif]

[Screenshot_ExternalEntry_Inspector.gif|/upfiles/1375970880594742.gif]

[object_introspector.JPG|/upfiles/13759708805920842.jpeg]

[buffer_content.JPG|/upfiles/13759708801854042.jpeg]

[Screenshot_Binary_Storage.gif|/upfiles/13759708802990742.gif]

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=3118]{quote}

asked 2009-06-03 04:24:45 -0500

theo gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

U can't query byte data type.
See the controlling serialization in the .Net doc. See the storage type property. This is what u might be looking for.
Shay

Attachments

  1. ScreenshotExternalEntryInspector.gif
  2. object_introspector.JPG
  3. buffer_content.JPG
  4. ScreenshotBinaryStorage.gif

answered 2009-06-03 14:55:42 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Hello Shay,

Thanks for the reference, it was quite interesting. I read this page: http://www.gigaspaces.com/wiki/displa...

It seems that there is some confusion in the documentation. It says "Non-primitive class members have to be marked with the Serializable attribute, meaning, they are serialized using default .NET serialization. Members implementing ISerializable can implement their own serialization". This contradicts .NET usage of the [Serializable] attribute. In .NET, the [Serializable] attribute is applied to classes (types). The Gigaspaces wiki says "members". [Serializable] cannot be applied to any member, only to class, struct, enum and delegate declarations (try it out, the C# compiler will complain).

The class is already marked as [Serializable] in my case, so it would seem that if I want custom serialization I could implement it.

Question 1: If I implement the .NET ISerializable interface, will it be used instead of the default formatter? Question 2: If I implement the .NET ISerializable interface, can I expect the same performance boost on my .NET space operations as for the "Externalizable" interface implementation on Java? (I saw the performance figures on http://www.gigaspaces.com/wiki/displa... and wonder if this applies to .NET as well)

I am still don't understand whether I need to implement custom serialization in .NET to avoid the XML output (see my other post in this thread).

Thank you for the help. h4. Attachments

[Screenshot_ExternalEntry_Inspector.gif|/upfiles/13759708818593427.gif]

[object_introspector.JPG|/upfiles/13759708811839927.jpeg]

[buffer_content.JPG|/upfiles/13759708813738827.jpeg]

[Screenshot_Binary_Storage.gif|/upfiles/13759708815218727.gif]

theo gravatar imagetheo ( 2009-06-05 01:34:03 -0500 )edit

Hi Theo,

The documentation might be misleading, you don't need to mark any member as serializable. It meant to say that if you have members in your class which are not primitives, their class type needs to be serializable, that's because by default, they will be serialized with .NET default serialization.

Regarding your questions: 1) Implementing serializable only affect on inner members in your class that are not primitives because of the reason I stated above. You have to realize that it can't affect the root class because they are being reconstruction in the space at their Java representation for matching, so there is no simple way to deserialize your custom serialization at the server without involving .NET code with your custom deserialization that needs to run at the server for that purpose. Inner classes by default are kept as byte array in the server so in that case it is doable since they are not fully deserialized to a java representation. 2) It will only apply for non primitive members like I've stated. Keep in mind that we give you the ability to serialize non primitive members with our own serialization mechanism which is faster than the default .NET one, this is done by applying the SpaceProperty(StorageType=StorageType.Binary) on a field.

If you want to take advantage of a custom serialization of your own, you can have a payload class inside the class you wish to keep at the space. That payload class should keep all the fields that are not needed for matching. Doing so will keep the payload class at its serialized form in the space and it will only deserialize the fields you need to match against.

Regarding the byte array issue, you don't need to worry, .NET byte array is stored as Java byte array in the space, as matter of fact, there's nothing that is being kept as an XML or anything of that sort. You can read in the page above how each .NET type is kept. Regarding the issues you experience with the UI, I'll check next week why you are seeing that.

Eitan

eitany gravatar imageeitany ( 2009-06-05 16:40:26 -0500 )edit

Hi Theo,

It seems that you managed to reach some views of the UI which are not the default ones. You should look at an object with the Object Introspector, either by double clicking the item row or right click and choose Object Introspector. There you should see a normal view of your object.

Eitan h4. Attachments

[Screenshot_ExternalEntry_Inspector.gif|/upfiles/1375970881835168.gif]

[object_introspector.JPG|/upfiles/13759708818786468.jpeg]

[buffer_content.JPG|/upfiles/13759708812794769.jpeg]

[Screenshot_Binary_Storage.gif|/upfiles/13759708811268769.gif]

eitany gravatar imageeitany ( 2009-06-07 11:00:35 -0500 )edit

Hello Eitan,

This does not seem to be the case. I use tab Space Browser > Grid Tree > Spaces > MyDataGrid > Classes > Service View > Classes List > Class + "Query" button > Query result list

Then, on the cell Payload, right-click + Show with viewer > HTML Plain-text/Hex-raw. Both of these show the same data and it is XML.

This happens when the array is defined as a public byte[] Payload property in the .NET class. When I annotate it this property with the [SpaceProperty(StorageType=StorageType.Binary)] attribute, the result view changes. See attached screen shot. Now, instead of the XML data, I see "com.gigaspaces.serialization.BinaryObject@4cb6999" in the HTML Plain-Text viewer.

So, none of the viewers actually show the true binary contents (e.g. byte values 4, 5, 6). I have some difficulty here to comprehend the difference between the actual internal storage structure and what is shown in the viewer. h4. Attachments

[Screenshot_ExternalEntry_Inspector.gif|/upfiles/13759708818260593.gif]

[object_introspector.JPG|/upfiles/13759708813845493.jpeg]

[buffer_content.JPG|/upfiles/13759708818538693.jpeg]

[Screenshot_Binary_Storage.gif|/upfiles/13759708815052593.gif]

theo gravatar imagetheo ( 2009-06-07 20:49:14 -0500 )edit

Hi Theo,

This is what I described, this views are not the defaults one, actually they are pretty old views that we consider removing.
Do not use Show with viewer, just double click the row or if you do right click, choose Object Introspector instead of Show with viewer.

You don't need to annotate the field with the StorageType.Binary. this is irrelevant for your case.

Eitan

Attachments

  1. ScreenshotExternalEntryInspector.gif
  2. object_introspector.JPG
  3. buffer_content.JPG
eitany gravatar imageeitany ( 2009-06-08 01:26:02 -0500 )edit
0

Hi Theo,

byte array is stored as byte array in the space and not xml. It is not clear what exactly you are experiencing. I've tried to reproduce it but couldn't. Can you maybe send a screen shot so we'll understand what view you are looking at?

Eitan h4. Attachments

[Screenshot_Object_Query_Result_Table_View.gif|/upfiles/13759708802267463.gif]

[Screenshot_Binary_View_of_Payload_Field.gif|/upfiles/13759708808830963.gif]

[Screenshot_Space_Schema_Of_Payload_Class.gif|/upfiles/13759708801412263.gif]

[Screenshot_XML_View_of_Payload_Field.gif|/upfiles/13759708804333563.gif]

answered 2009-06-03 06:54:38 -0500

eitany gravatar image
edit flag offensive delete link more

Comments

Hello Eitan,

That's also my assumption, it should just be a plain old binary array... The debug log looks like this for the field: Fields[4].Name: Payload Fields[4].FieldType: System.Byte[] Fields[4].Metadata.AliasName: Payload Fields[4].SpaceTypeName: [B Fields[4].Metadata.StorageType: Object Fields[4].Metadata.Index: None Fields[4].Metadata.NullValue:
Fields[4].TypeInfo.SpaceTypeCode: ByteArray

I've attached four screenshots from the console. In the query result, you can see I've put two objects to the space which have the payload field. In the space schema, the field is of type "[B" (not sure what it means). In the binary and xml view of the "Payload" field, it looks like the data is stored as XML. The array is just { 4, 5, 6 }. h4. Attachments

[Screenshot_Object_Query_Result_Table_View.gif|/upfiles/1375970880309783.gif]

[Screenshot_Binary_View_of_Payload_Field.gif|/upfiles/1375970880301283.gif]

[Screenshot_Space_Schema_Of_Payload_Class.gif|/upfiles/13759708808016983.gif]

[Screenshot_XML_View_of_Payload_Field.gif|/upfiles/13759708809376983.gif]

theo gravatar imagetheo ( 2009-06-04 22:18:14 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2009-06-03 04:24:45 -0500

Seen: 125 times

Last updated: Jun 03 '09