I have to write a proxy client in Java to connect to JSON WebService. I have only textual description of WebService methods and types. For instance the result of one method is
Params {
byte[] challenge;
byte[] proff;
}
If I create a class Params in Java with both fields as byte[], jackson mapper treats them as binary arrays and encodes as following example
{"id":2,"method":"Authenticate","params":["bSwY+kKRO7sIJNZFG/L3dK2ke1kIDwzyK5n717MyBG1pnRhjqSF0kRMAyEqLYKA6VBwujaR8K/wr98+G1Av9vQ12soFi+3DViPN4YDguqF0=","2iNJ5UEK3eVxFTEUHMN04QM8WtNrwGSIu1hKVXFMVvQ="]}
The WebService exptects those parameters in a form of comma separated non negative byte values like
[truncated] {"id":2,"method":"Authenticate","params":[[114,109,104,101,70,88,16,32,102,17,117,3,105,104,112,4,39,103,11,54,90,106,90,69,26,20,5,10,121,52,108,64,106,102,52,124,87,8,21,29,28,119,110,70,122,33,105, ...............
I concluded that Jackson mapper uses some kind of automatic Java type recognition and chooses the corresponding JSON type. Is there a way to control it and ie change the type the serializer should use for particular Java type serialization? Where is description and mapping between Java and JSON types?
Regards
Jackson is representing the byte[] as a base 64 encoded string.
You’ll need to implement a custom serializer, to manually iterate through the byte[] and generate the JSON array of integer values.
That didn’t work out quite as I expected it should.