In Jackson 2.4, you can convert as follows:

MyClass newJsonNode = jsonObjectMapper.treeToValue(someJsonNode, MyClass.class);

where jsonObjectMapper is a Jackson ObjectMapper.


In older versions of Jackson, it would be

MyClass newJsonNode = jsonObjectMapper.readValue(someJsonNode, MyClass.class);
Answer from icedtrees on Stack Overflow
🌐
Baeldung
baeldung.com › home › json › jackson › convert jackson jsonnode to typed collection
Convert Jackson JsonNode to Typed Collection | Baeldung
June 21, 2025 - Let’s define a Person class that ...ers/setters } If we want to read an object from the entire JSON, we can use the ObjectMapper class of Jackson to do so: JsonNode rootNode = new ObjectMapper().readTree(jsonString); JsonNode childNode ...
Discussions

java - Convert JsonNode into Object - Stack Overflow
But I'm not very happy with this ... my JsonNode into a String representation before it is deserialized into a POJO. The performance is an issue for me in this case. ... Well, you could query the node to see what type it is and then deal with it as its "real" type. And, if necessary, write a MyObject(jsonObject object) constructor ... More on stackoverflow.com
🌐 stackoverflow.com
Does it consider a bad practice to use jsonNode as the return type
Normally devs prefer to have a POJO/DTO class dedicated for your specific domain model. And when you de-serialize your JSON you don't use JsonNode, but your specific type. Like this: try { Book book = new ObjectMapper().readValue(jsonString, Book.class); } catch (JsonProcessingException e) { // do something when it goes wrong } This approach has some benefits, for example: immediately getting an exception if your JSON has wrong or not matching structure having a proper POJO gives you all OOP benefits, including your custom methods in your class, getters, setters and so on JsonNode is used when you're processing something super generic or unexpected, so you're not sure what structure this JSON has and you prefer to have a "safe" container, not giving you any exceptions. As for ResponseEntity - It's a common practice to have it as a return type from you REST controllers, with some typisation normally, like ResponseEntity for example. You wrapping ResponseEntity object into another object - DeferredResult, it makes no sense. Probably, makes sense to do it other way around - ResponseEntity, but it's hard to say not knowing your logic or domain model. Why do you want ResponceEntity as your controller return type? this class purpose is exactly this - wrap your response object into handy class with all HTTP things embedded you can easily configure your HTTP status and headers with this class in has a lot of methods and builders to do it in a concise manner More on reddit.com
🌐 r/learnjava
11
4
June 14, 2024
java - How to parse a JSON string into JsonNode in Jackson? - Stack Overflow
For me, passing JsonNode was apparently necessary to prevent Jackson from deserializing it as something else - which would have failed. 2015-02-26T03:44:06.063Z+00:00 ... Richard's answer is correct. Alternatively you can also create a MappingJsonFactory (in org.codehaus.jackson.map) which knows where to find ObjectMapper... More on stackoverflow.com
🌐 stackoverflow.com
How to parse Json array with 2 or more different types using Jackson?

http://www.baeldung.com/jackson-inheritance

You'll need to have those types inherit from one base class though.

Also; that is really bad JSON.

More on reddit.com
🌐 r/javahelp
11
4
January 15, 2018
🌐
Baeldung
baeldung.com › home › json › jackson › how to convert jsonnode to objectnode
How to Convert JsonNode to ObjectNode | Baeldung
June 21, 2025 - In this tutorial, we’ll еxplorе ... in Java. This is a necessary step when we need to manipulate the data directly in our code. JsonNode is an abstract class in the Jackson library that represents a node in the JSON tree. It’s the base class for all nodes and is capable of storing different types of data, including objects, arrays, strings, ...
🌐
Medium
medium.com › @salvipriya97 › jsonnode-explained-with-examples-d0c05324f61d
JsonNode explained with examples. What is JsonNode in Java? | by Priya Salvi | Medium
July 2, 2024 - Serialization: The transformed JsonNode is serialized back into a JSON string using ObjectMapper.writeValueAsString(). JsonNode is a powerful tool in Java for working with JSON data dynamically and flexibly.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Jackson JsonNode to Java Collections - Java Code Geeks
July 8, 2024 - The module is registered with the ObjectMapper, which then converts the JsonNode to a Person object. ... Run the Main class. The output should display the deserialized Person object, including the address and phone numbers. ... In this article, we explored various methods for converting Jackson JsonNode objects into typed Java collections.
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-jsonnode.html
Jackson JsonNode
The Jackson JsonNode class is the Jackson tree object model for JSON. Jackson can read JSON into an object graph (tree) of JsonNode objects. Jackson can also write a JsonNode tree to JSON.
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-objectmapper.html
Jackson ObjectMapper
This is similar to parsing a JSON string (or other source) into a Java object with the Jackson ObjectMapper. The only difference is, that the JSON source is a JsonNode.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › jackson › jackson_tree_to_object.htm
Jackson - Tree to Java Objects
In this example, we've created a Tree using JsonNode and write it to a json file and read back tree and then convert it as a Student object. package com.tutorialspoint; import java.io.File; import java.io.IOException; import java.util.Arrays; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; public class JacksonTester { publi
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.7.0 API)
Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules. If representation can not be converted to an int (including structured types like Objects and Arrays), default value of 0 will be returned; no exceptions are thrown.
🌐
Attacomsian
attacomsian.com › blog › jackson-convert-java-object-to-json-node
Convert Java Object to JsonNode using Jackson
October 14, 2022 - try { // create a map Map<String, ... } To convert an instance of JsonNode to a Java Object, you can use the treeToValue() method from ObjectMapper:...
🌐
Medium
cowtowncoder.medium.com › jackson-tips-objectnode-putpojo-putrawvalue-for-fun-and-profit-358f8f3b8580
Jackson Tips: ObjectNode.putPOJO(), putRawValue() for fun and profit | by @cowtowncoder | Medium
September 29, 2021 - ObjectMapper mapper = new JsonMapper(); JsonNode root = mapper.readTree(jsonContent); double value = root.at("/properties/value").asDouble(); You can also conveniently convert between Java representations like so: // assuming MyValue has compatible structure MyValue value = mapper.treeToValue(root, MyValue.class); // converting to Map fine as well: Map<String, Object> map = mapper.treeToValue(root, Map.class);
🌐
CodingTechRoom
codingtechroom.com › question › convert-jsonnode-to-object-java
How to Convert a JsonNode into a Java Object? - CodingTechRoom
ObjectMapper objectMapper = new ObjectMapper(); MyObject myObject = objectMapper.treeToValue(jsonNode, MyObject.class); Converting a `JsonNode` to a Java object is a common task when working with JSON data in Java applications.
🌐
DEV Community
dev.to › abharangupta › dive-into-jackson-for-json-in-java-understanding-jsonnode-arraynode-and-objectmapper-30g4
Dive into Jackson for JSON in Java: Understanding JsonNode, ArrayNode, and ObjectMapper - DEV Community
October 22, 2024 - We use ObjectMapper again, but this time it reads a JSON string and converts it back into a Person object. This is done using readValue(), and the result is a full Java object ready to be used in your code. And there you have it!
🌐
Reddit
reddit.com › r/learnjava › does it consider a bad practice to use jsonnode as the return type
r/learnjava on Reddit: Does it consider a bad practice to use jsonNode as the return type
June 14, 2024 -

I am a beginner of Java & Springboot. I feel like I am doing something that does not use the full strength of spring boot, e.g. using JsonNode & return untyped Response Entity etc.

Just wonder if there is any best practice when dealing with this kind of situation, when I want to return an object as part of result.

In Typescript I can create an interface for the object, how about in java / Springboot?

TestService.java

...
@Service
@Slf4j
public class TestService {
    private final TsKvRepository tsKvRepository;
    private final ObjectMapper objectMapper = new ObjectMapper();

    @Autowired
    public TestService(TsKvRepository tsKvRepository) {
        this.tsKvRepository = tsKvRepository;
    }

    public DeferredResult<ResponseEntity> getLatestTimeseries(String entityIdStr, String eui64) {
        DeferredResult<ResponseEntity> result = new DeferredResult<>();

        try {
            UUID entityId = UUID.fromString(entityIdStr);
            List<TsKvEntity> tsList =  this.tsKvRepository.findLatestByEui64(entityId, eui64);

            if (!tsList.isEmpty()) {
                TsKvEntity tsKvEntity = tsList.get(0);
                JsonNode jsonNode = objectMapper.readTree(tsKvEntity.getJsonValue());
                
                ResponseEntity<?> responseEntity = new ResponseEntity<>(jsonNode.get(0), HttpStatus.OK);
                result.setResult(responseEntity);
            } else {
                ResponseEntity<?> responseEntity = new ResponseEntity<>("No data found", HttpStatus.NOT_FOUND);
                result.setResult(responseEntity);
            }

        }catch(IllegalArgumentException | NullPointerException e) {
            ResponseEntity<?> responseEntity = new ResponseEntity<>("Invalid UUID format or null keysStr: " + e.getMessage(), HttpStatus.BAD_REQUEST);
            result.setResult(responseEntity);
        } catch (JsonMappingException e) {
            throw new RuntimeException(e);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        return result;
    }

}
Top answer
1 of 3
8
Normally devs prefer to have a POJO/DTO class dedicated for your specific domain model. And when you de-serialize your JSON you don't use JsonNode, but your specific type. Like this: try { Book book = new ObjectMapper().readValue(jsonString, Book.class); } catch (JsonProcessingException e) { // do something when it goes wrong } This approach has some benefits, for example: immediately getting an exception if your JSON has wrong or not matching structure having a proper POJO gives you all OOP benefits, including your custom methods in your class, getters, setters and so on JsonNode is used when you're processing something super generic or unexpected, so you're not sure what structure this JSON has and you prefer to have a "safe" container, not giving you any exceptions. As for ResponseEntity - It's a common practice to have it as a return type from you REST controllers, with some typisation normally, like ResponseEntity for example. You wrapping ResponseEntity object into another object - DeferredResult, it makes no sense. Probably, makes sense to do it other way around - ResponseEntity, but it's hard to say not knowing your logic or domain model. Why do you want ResponceEntity as your controller return type? this class purpose is exactly this - wrap your response object into handy class with all HTTP things embedded you can easily configure your HTTP status and headers with this class in has a lot of methods and builders to do it in a concise manner
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
GitHub
gist.github.com › diegoicosta › f06f61720f02b8c00afddb146ade5cce
Using Jackson to create manually a JsonNode · GitHub
Using Jackson to create manually a JsonNode · Raw · JsonJacksonTest.java · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › cloud-service › javadoc › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (The Adobe Experience Manager SDK 2022.11.9850.20221116T162329Z-220900)
Method that will try to convert value of this node to a Java boolean. JSON booleans map naturally; integer numbers other than 0 map to true, and 0 maps to false and Strings 'true' and 'false' map to corresponding values. If representation cannot be converted to a boolean value (including structured types like Objects and Arrays), specified defaultValue will be returned; no exceptions are thrown. public <T extends JsonNode> T require() throws java.lang.IllegalArgumentException
🌐
MarkLogic
docs.marklogic.com › datahub › javadocs › 5.1.0 › com › marklogic › hub › util › json › JSONObject.html
JSONObject (marklogic-data-hub 5.1.0 API)
public static com.fasterxml.jackson.databind.JsonNode readInput(java.io.Reader reader) throws java.io.IOException ... public static java.lang.String writeValueAsString(java.lang.Object obj) throws com.fasterxml.jackson.core.JsonProcessingException