디버거에서 IntelliJ Idea의 JSON 개체 가져오기
디버거에서 전체 객체를 Json으로 가져올 수 있습니까?옵션이 있습니다.View text
하지만 어떻게 해서든View JSON
?
EDIT: 코멘트에 기재되어 있듯이, 이것은 완벽하지 않습니다.변수에 따라서는 「stack overflow」응답이 발생합니다.
@Mr.Han의 답변에서 제시된 바와 같이 이를 수행할 수 있는 방법은 다음과 같습니다.
Intelij 디버거에서 개체를 json으로 표시하는 새로운 방법을 추가합니다.
- 에 가는 것
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);
또는 다음과 같이 디버깅워처 내에서 다음 코드를 사용할 수도 있습니다.
new ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.writerWithDefaultPrettyPrinter()
.writeValueAsString( myObject )
이 코드 프래그먼트는 IntelliJ의 Evaluate Expression(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 );
IntelliJ에서는 Show as ... 플러그인을 사용할 수 있습니다.
디버거 및 콘솔에서 포맷된 데이터를 표시하는 작은 플러그인입니다.
IntelliJ의 내장 포맷 기능을 사용합니다.더 이상 디버거나 콘솔에서 파일 형식으로 값을 복사할 필요가 없습니다.지원되는 형식은 JSON, SQL, XML, Base64 인코딩된 JSON, Base64 인코딩된 텍스트입니다.
가지고 계신 경우gson
프로젝트의 종속성 워치 변수를 생성할 수 있습니다.
new GsonBuilder().setPrettyPrinting().create().gson.toJson(myObject)
어디에myObject
당신의 목표입니다.
파일 | 설정 | 빌드, 실행, 전개 | 디버거 | 데이터 뷰 | Java 타입 렌더러, + 를 클릭하여 새 렌더를 추가합니다.copy is OK:) 다른 jar를 선택하여 포맷할 수 있습니다.
이제 신청하고 참여하세요~
@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);
렌더러를 보다 복잡한 오브젝트에 대해 작업시키는 데 어려움을 겪고 있는 경우 - 아래에서 결합된 JSON 렌더러를 찾을 수 있습니다.
- https://stackoverflow.com/a/60189764/3837638
- https://stackoverflow.com/a/69802068/3837638
- https://stackoverflow.com/a/63060407/3837638
다음 렌더러는 클래스 계층에서 동일한 이름을 가진 여러 필드를 식별하는 데 도움이 되었기 때문에 변경할 수 있었습니다.
처음에는 Illigal Argument를 사용하고 있었습니다.분석할 수 없는 중첩된 개체의 직렬화에 대한 예외입니다.
시리얼라이제이션 중에 문제가 발생했을 경우 이 렌더러를 사용하여 콘솔에서 수정해야 하는 예외에서 스택트레이스를 찾을 수 있습니다
행운을 빕니다.
if (null == this)
return "null";
if (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;
}
try {
String json = new GsonBuilder().setPrettyPrinting().create().toJson(this);
return json;
} catch (Exception e) {
e.printStackTrace();
}
Intelij 플러그인 디버깅 변수 추출 또는 상세 정보 사용 - https://plugins.jetbrains.com/plugin/16362-debug-variable-extractor
언급URL : https://stackoverflow.com/questions/53776048/get-object-as-json-in-intellij-idea-from-debugger
'programing' 카테고리의 다른 글
XMLHTTPRequest를 사용하여 변수를 전달하려면 어떻게 해야 합니까? (0) | 2023.03.12 |
---|---|
워드프레스.우코머스카트에 추가하기 전에 작업 후크 (0) | 2023.03.12 |
INSERT 문에서 "여기에 열이 허용되지 않습니다" 오류가 발생했습니다. (0) | 2023.03.12 |
Angular의 'scope'를 사용하여 다른 컨트롤러에서 컨트롤러의 메서드를 호출합니다.JS (0) | 2023.03.12 |
스크립트로 인해 "인라인 스크립트 실행 거부:인라인 실행을 활성화하려면 'unsafe-inline' 키워드, 해시 또는 난스가 필요합니다." (0) | 2023.03.12 |