Created
February 17, 2015 22:14
-
-
Save emilong/2d557161f46c5f654531 to your computer and use it in GitHub Desktop.
How Gson serializes a byte array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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