给定以下纯文本 JSON 对象
class Chat {
String id;
String title;
List<String> messages;
}
如何重写toString
以使其人类可读仅用于调试?
最佳答案
您可以将其序列化为 JSON 字符串:
class Chat {
private static final GSON = new GSON();
String id;
String title;
List<String> messages;
public String toString() {
return BuildConfig.DEBUG ? GSON.toJson(this) : super.toString();
}
}
关于android - 如何将 POJO 转换为 Android 上可读的字符串以进行调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47837569/