Skip to content

Instantly share code, notes, and snippets.

@emilong
Created February 17, 2015 22:14
Show Gist options
  • Save emilong/2d557161f46c5f654531 to your computer and use it in GitHub Desktop.
Save emilong/2d557161f46c5f654531 to your computer and use it in GitHub Desktop.
How Gson serializes a byte array
import com.google.gson.Gson;
import java.security.MessageDigest;
public class GsonTest {
private final byte[] sha1;
public GsonTest(byte[] sha1) {
this.sha1 = sha1;
}
public static void main(String[] args) throws Exception {
MessageDigest md = MessageDigest.getInstance("SHA1");
GsonTest gt = new GsonTest(md.digest());
System.out.println(new Gson().toJson(gt));
// Prints: {"sha1":[-38,57,-93,-18,94,107,75,13,50,85,-65,-17,-107,96,24,-112,-81,-40,7,9]}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment