I’ve been trying for a while to get a byte[] from my database blob and then parse it to json and send it to my clients. I first get the blob from the database and then I get the byte array by doing:
MyObject temp = new MyObject()
Blob icon = dbResult.getBlob(1);
temp.setIcon(icon.getBytes(1, (int)icon.length()));
Later on I parse MyObject to a json string which I send back to clients. But it seems that the json string becomes pretty much corrupted when parsing the byte[].
An example of how it might look:
[{"icon":"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAFQAPwDASIAAhEBAxEB/8QAHAAAAQUBAQEAAAAAAAAAAAAAAgEDBAUGAAcI
I parsed this to json in my webservice which is a jersery webservice. When i try to parse it from json into a class object at client side, it throws IllegalStateException(Gson).
Anyone knows what this is about and what i’m doing wrong?
If you try to transfer binary data using json, you better explicitly encode it with base64 and then decode it on receiver’s side. JSON isn’t designed to wrap binaries, so the problems when trying to make this were expectable.