How could I serialize and deserialize DataTable across C# and Java

323 views
Skip to first unread message

avei shriety

unread,
Apr 25, 2022, 11:43:17 PM4/25/22
to Protocol Buffers
A request from C# is sent to Java Server, and in Server, it will call .Net Core to serialize the C# DataTable. So I could get the binaryData(like byte[] format). When the binaryData return to C#, C# could use binFormatter.Deserialize()  to get the correct DataTable.

I could get the serialize binaryData in Java Server, such as byte[] value = response.get(key_name). And now I wonder that how I can deserialize this binaryData in Java Server, can use protobuf to deserialize?

Marc Gravell

unread,
Apr 26, 2022, 2:09:10 AM4/26/22
to avei shriety, Protocol Buffers
OK. To share data between platforms, you need two things:

1. A shared data layout
2. A shared serialization protocol

For 1: the inbuilt DataTable layout is implementation specific. There is no shared (/common/agreed) shape that both .NET and Java both use, so: nothing is readily available out of the box here. Instead of using DataTable, I would strongly suggest either a DTO defined via something like a shared schema (such as .proto, but let's not get ahead of ourselves), or if you are using unpredictable data (since DataTable is often used ad-hoc): something much less formal - maybe just CSV/TSV

For 2: protobuf could indeed help with this bit, if we define a shared schema in 1; however, your question suggests you're using BinaryFormatter, in which case please let me emphasize: *whatever route you go*: don't use BinaryFormatter. It will hurt you - the only question is when.

On Tue, 26 Apr 2022, 04:36 'avei shriety' via Protocol Buffers, <prot...@googlegroups.com> wrote:
A request from C# is sent to Java Server, and in Server, it will call .Net Core to serialize the C# DataTable. So I could get the binaryData(like byte[] format). When the binaryData return to C#, C# could use binFormatter.Deserialize()  to get the correct DataTable.

Now I wonder that how I can get the byte[] Data in Java, which is serialized by .Net Core binFormatter.Serialize()? Or I just wonder that how I could get this serialized data like coding "String ss = data.getString("SS")"

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/24eb176c-bc77-4ae3-a639-5b127ae4a8c2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages