Mic*_*u93 6 debugging json intellij-idea
Is it possible to get the whole object from debugger as Json?
There is an option View text
but can I somehow View JSON
?
Bra*_*rks 29
编辑:如评论中所述,这并不完美,对于某些变量,您将获得“stackoverflow”响应
File | Settings | Build, Execution, Deployment | Debugger | Data Views | Java Type Renderers
+
以添加新渲染器JSON renderer
java.lang.Object
为Apply renderer to objects of type
Use following expression:
并提供这样的表达式:if (null == this || this instanceof String)
return this;
new com.google.gson.GsonBuilder().setPrettyPrinting().create().toJson(this);
Run Code Online (Sandbox Code Playgroud)
Lut*_*hes 19
您可以在 IntelliJ 上的评估表达式(Alt + F8)中尝试此代码片段:
new com.fasterxml.jackson.databind.ObjectMapper() .registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()) .disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writerWithDefaultPrettyPrinter() .writeValueAsString( myObject );
Run Code Online (Sandbox Code Playgroud)
Rla*_*que 10
另外,由于看到这里,你可以使用下面的代码在你的调试守望者:
new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.writerWithDefaultPrettyPrinter()
.writeValueAsString( myObject )
Run Code Online (Sandbox Code Playgroud)
您可以为 IntelliJ使用Show as ...插件。
一个小插件,用于在调试器和控制台之外显示格式化数据。
使用 IntelliJ 的内置格式化功能。不再需要将值从调试器或控制台复制到文件中以在那里格式化它们。支持以下格式:JSON、SQL、XML、Base64 编码的 JSON、Base64 编码的文本
如果gson
您的项目有依赖性,您可以创建一个监视变量
new GsonBuilder().setPrettyPrinting().create().gson.toJson(myObject)
Run Code Online (Sandbox Code Playgroud)
你的对象在哪里myObject
。
按照@BradParks 的说明进行操作,并使用以下表达式。
对我来说,如果没有完全限定的类名,它就无法工作。我还对ObjectMapper
. 由于某种我不明白的原因,即使我已Apply renderers to object of type
设置为java.lang.Object
,我也需要this
像(Object)this
用作方法的参数时那样进行类型转换writeValueAsString()
。
if (this == null
|| this instanceof CharSequence
|| this instanceof Number
|| this instanceof Character
|| this instanceof Boolean
|| this instanceof Enum) {
// Here you may add more sophisticated test which types you want to exclude from the JSON conversion.
return this;
}
new com.fasterxml.jackson.databind.ObjectMapper()
.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule())
.disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.setVisibility(
com.fasterxml.jackson.annotation.PropertyAccessor.FIELD,
JsonAutoDetect.Visibility.ANY)
.setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
.writerWithDefaultPrettyPrinter()
.writeValueAsString((Object)this);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2505 次 |
最近记录: |