Last active
March 26, 2019 21:43
-
-
Save landsman/5cc73039b661b5e6105d5fea4496dd3b to your computer and use it in GitHub Desktop.
dump whatever object type you want to console output, inspired by https://dzone.com/articles/introduction-to-json-with-java
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 helper; | |
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
public final class DevTools | |
{ | |
public static String dump(Object stuff) throws JsonProcessingException { | |
System.out.println(convertObject(stuff)); | |
return null; | |
} | |
public static String dump(Object stuff, String prefix) throws JsonProcessingException { | |
System.out.println(prefix + " - " + convertObject(stuff)); | |
return null; | |
} | |
public static String dump(String stuff) { | |
System.out.println(stuff); | |
return null; | |
} | |
public static String dump(String stuff, String prefix) { | |
System.out.println(prefix + " - " + stuff); | |
return null; | |
} | |
private static String convertObject(Object stuff) throws JsonProcessingException { | |
ObjectMapper mapper = new ObjectMapper(); | |
return mapper.writeValueAsString(stuff); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment