Last active
August 20, 2018 09:23
-
-
Save bryanmaina/a3b44ad1229e17d0186881340aa8fe9b to your computer and use it in GitHub Desktop.
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
package com.example.tools; | |
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
public class ThreadStackPrinter { | |
private static Gson gson = new GsonBuilder() | |
.setPrettyPrinting() | |
.serializeNulls() | |
.enableComplexMapKeySerialization() | |
.create(); | |
public static void printObjectAsJson(Object object) { | |
StackTraceElement callingMethodStack = Thread.currentThread().getStackTrace()[2]; // method from which we are printing | |
System.out.println(new StringBuilder() | |
.append("====================== ").append(callingMethodStack.toString()).append(" ==========================") | |
.append(System.lineSeparator()) | |
.append(gson.toJson(object)) | |
.append(System.lineSeparator()) | |
.append("================================================")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment