-1

We are trying to convert a Java Class instance to JSON by using GSON library. This class includes a ByteBuffer instance as a member that is created by allocateDirect.

Due to the fact that ByteBuffer created by allocateDirect holds data in Native memory area, GSON fails to serialize this field to JSON.

How can we customize/configure GSON to handle ByteBuffer's native data ?

Thanks...

AGP
  • 459
  • 1
  • 6
  • 20
  • Well, how do you write to this `ByteBuffer` from your class? – fge Apr 12 '14 at 20:03
  • Have you read [this](https://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserialization)? – kdgregory Apr 12 '14 at 20:16
  • I am not able reach that web page, – AGP Apr 13 '14 at 14:11
  • That's too bad. It's always easier to develop software when you can read the documentation for the tools you use. Perhaps you can find someone that does have access and ask him/her to print it for you. Once you've done that, if you still have problems post your code and describe your *exact* problem. – kdgregory Apr 14 '14 at 12:47

1 Answers1

1

I found it,

It was easy, simple add Serializer&Deserializer for ByteBuffer class.

In serialization, it is possible convert directdata to byte[] and serialize. Converting byte[] to base64 and using that output for serialization is a plus(brings space savings in output).

AGP
  • 459
  • 1
  • 6
  • 20