Skip to content

Instantly share code, notes, and snippets.

@landsman
Last active March 26, 2019 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save landsman/5cc73039b661b5e6105d5fea4496dd3b to your computer and use it in GitHub Desktop.
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
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