So, something like that you may have to build out yourself. However, I found that this question has been asked before. And it's been recommend to use the following resource:

http://www.jsonschema2pojo.org/

or go through the headache and build out this feature. Original: Generate Java class from JSON?

Answer from TheoNeUpKID on Stack Overflow
🌐
JetBrains
plugins.jetbrains.com › plugin › 8533-json2pojo
Json2Pojo Plugin for IntelliJ IDEA & Android Studio
Allows for easy creation of Java POJOs from JSON, with GSON annotations and accessors. Once installed, just right-click on the destination package and choose "New...
🌐
JetBrains
plugins.jetbrains.com › plugin › 8634-robopojogenerator
RoboPOJOGenerator - IntelliJ IDEs Plugin | Marketplace
Intellij Idea and Android Studio plugin for JSON to POJO transformation. Generates Java, Java Records and Kotlin POJO files from JSON: GSON, FastJSON, AutoValue...
🌐
GitHub
github.com › jineshfrancs › AwesomePojoGenerator
GitHub - jineshfrancs/AwesomePojoGenerator: Intellij Plugin to generate Pojo class from json · GitHub
5.Click on Restart IDE button to restart the IDE for completing plugin installation. 1.Right click on the package in which you want to generate the pojo classes -> click on new -> click on new Java class from Json ·
Starred by 25 users
Forked by 7 users
Languages   Java
🌐
JetBrains
plugins.jetbrains.com › plugin › 13733-pojo-to-json-schema
POJO to JSON Schema - IntelliJ IDEs Plugin | Marketplace
Generates JSON Schemas from Java classes. Generated json schemas locates under .generated-json-schemas folder. How to use Right click on Java class: Click POJO to JSON...
🌐
JetBrains
plugins.jetbrains.com › plugin › 12066-pojo-to-json
POJO to JSON Plugin for IntelliJ IDEA & Android Studio
POJO to JSON A simple plugin for converting POJO to JSON in IntelliJ IDEA Support any type you can think of in Java.Support Java17 and lastSupport Java14 Records...
Top answer
1 of 12
109

EDIT: as noted in the comments, this is not perfect, as for some variables you will get a "stackoverflow" response

As suggested by @Mr Han's answer, here's how you can do this:

Add a new way to view objects in IntelliJ debugger as JSON by:

  • Going to File > Settings > Build, Execution, Deployment > Debugger > Data Views > Java Type Renderers
  • Click + to add new renderer
  • Call it JSON renderer
  • Supply java.lang.Object for Apply renderer to objects of type
  • Choose Use following expression and supply an expression like:

If you have Gson dependency in the classpath:

if (null == this || this instanceof String)
  return this;

new com.google.gson.GsonBuilder().setPrettyPrinting().create().toJson(this);

or if you have Jackson dependency in classpath:

if (null == this || this instanceof String)
  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).writerWithDefaultPrettyPrinter() .writeValueAsString(this);
  • Click OK
  • Now when you choose Copy Value on a variable, it will copy as JSON.

Note: If you don't want to change the default behavior, create a "default" renderer also with "use default renderer" settings, and put it first in the list, it will use that as default and you can switch to JSON on demand by right click on debugged variable -> use renderer: JSON Renderer.

2 of 12
30

Alternatively, as seen here, you can use the following piece of code in your debug watcher:

new ObjectMapper()
    .setSerializationInclusion(JsonInclude.Include.NON_NULL)
    .writerWithDefaultPrettyPrinter()
    .writeValueAsString( myObject )
🌐
JetBrains
plugins.jetbrains.com › plugin › 8062-json-model-generator
JSON Model Generator Plugin for IntelliJ IDEA & Android ...
Tool to covert JSON string to Java class. * Support get JSON string from URL or user's input. * Support data conversion library like fastjson. * Support auto...
Find elsewhere
🌐
JetBrains
plugins.jetbrains.com › plugin › 15766-my-pojo-to-json
My Pojo To Json - IntelliJ IDEs Plugin | Marketplace
A simple plugin for converting Java bean to Json usages: Open any java code file in idea. Right click the class name or java type to open the context menu. Click the...
🌐
JetBrains
plugins.jetbrains.com › plugin › 9686-pojo-to-json
POJO to JSON - IntelliJ IDEs Plugin | Marketplace
选中类-右键-MakeJson 将简单Java类型转成JSON 方便用postman或者curl的时候构造JSON body Convert POJO to JSON, easy to construct JSON body when you want posting a request throw Postman or...
🌐
JetBrains
plugins.jetbrains.com › plugin › 14603-java-json-convertor
Java Json Convertor - IntelliJ IDEs Plugin | Marketplace
Plugin to convert Json file to Java file and vice versa. Java To Json Converter 1. Place the Java file into any java package. 2. Right-click on valid Java pojo file...
🌐
JetBrains
plugins.jetbrains.com › plugin › 10336-java-bean-to-json
Java Bean to Json - IntelliJ IDEA & Android Studio Plugin
March 1, 2021 - GitHub | Donate with PayPal | A simple plugin for converting Java bean to JSON When you post json request using Postman :).
🌐
JetBrains
plugins.jetbrains.com › plugin › 11486-json2pojo-with-lombok
Json2Pojo with Lombok - IntelliJ IDEs Plugin | Marketplace
Create POJOs from JSON, with lombok and gson/jackson annotations and accessors. Once installed, just right-click on the destination package and choose "New -&gt...
🌐
JetBrains
plugins.jetbrains.com › plugin › 7678-jackson-generator-plugin
Jackson Generator Plugin - IntelliJ IDEs Plugin | Marketplace
This plugin allows you to generate Jackson ready java files from provided Json formatted string. How to use: Select folder from Project Window , click RMB (right mouse...
🌐
GitHub
github.com › HexarA › Json2Pojo
GitHub - HexarA/Json2Pojo: IntelliJ plugin that allows for easy creation of Java POJOs from JSON, with GSON annotations and accessors.
Install the plugin in IntelliJ / Android Studio by opening Preferences -> Plugins -> Search for "Json2Pojo". Right-click on the target package, select New -> "Generate POJOs from JSON". Enter the root class name and enter your source JSON text.
Starred by 71 users
Forked by 32 users
Languages   Java 100.0% | Java 100.0%
🌐
JetBrains
plugins.jetbrains.com › plugin › 9693-build-json
Build JSON - IntelliJ IDEs Plugin | Marketplace
Create toJson() method in java file automatically use alt+insert - toJson()
🌐
YouTube
youtube.com › shorts › A7tvETUEnMw
IntelliJ Productivity Hack: Generate POJO from JSON with this.. - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published   July 9, 2023
🌐
Baeldung
baeldung.com › home › json › generate a java class from json
Generate a Java Class From JSON | Baeldung
May 11, 2024 - First, we’ll create a method convertJsonToJavaClass that converts a JSON file to a POJO class and accepts four parameters: ... Then, we’ll define the configuration for jsonschema2pojo, which lets the program identify that the input source ...
🌐
GitHub
github.com › GoodforGod › DummyMapper
GitHub - GoodforGod/DummyMapper: IntelliJ IDEA plugin for mapping Java class to JSON/AVRO/GraphQL.
Plugin uses DummyMaker library for generating classes and then converting to JSON format.
Starred by 17 users
Forked by 2 users
Languages   Java 100.0% | Java 100.0%
🌐
JetBrains
plugins.jetbrains.com › plugin › 26887-java-generate-json-schema
Java Generate Json Schema - IntelliJ IDEs Plugin | Marketplace
Generate JSON Schema from Java classes with support for nested objects, Javadoc comments, and customizable output formats. Compatible with IntelliJ 2024.3+.