The version of EncryptedInteger
you link to isn't the one you're using.
The one you're using is this one (The current version).
The difference is that it includes this line:
private Class bigi;
And it assigns BigInteger.class
to it.
Gson can't serialize that, and that's what is throwing that exception.
You're going to have to write a custom serializer / deserializer to handle that class. The section for this in the Gson user guide should get you started. There's also numerous questions/answers on SO covering the subject.
Edit from comments:
I didn't look at it much further. Looking at it now, I mean, it uses that for something. It also holds an instance of java.util.Random
.
Looking at it a little more in-depth ... you kind of have a problem serializing/deserializing it the way it sits. There's no constructor or public method to set the encrypted value. The method that would be useful for that is private
(setCipherVal()
). If that were public you could just write a serializer that outputs JSON holding the PublicKey
and the encrypted value, then in your deserializer use those to create a new EncryptedInteger
.
Without changing that class to allow for that I don't see a way to serialize/deserialize it to JSON.
Last edit: Actually, you could, it's just ugly because you have to use reflection to set the cipherval
directly after constructing the EncryptedInteger
with just the PublicKey