Spring Boot & JsonNode: How to use it and when to turn to creating Custom Deserializers

preview_player
Показать описание
Are you a Spring developer looking to up your game in handling JSON data? Look no further! This comprehensive tutorial is designed to introduce you to the power of JsonNode—a must-know tool for traversing JSON trees effortlessly. But that's not all! We'll also dive into the art of writing custom deserializers, an invaluable skill for those special cases where the default just won't cut it. Whether you're a beginner or just looking to sharpen your skills, this video has something for everyone. Learn how to navigate complex JSON structures and tailor your deserialization process to fit specific needs, all while using the Spring framework you know and love.

🔗Resources & Links mentioned in this video:

👋🏻Connect with me:

Рекомендации по теме
Комментарии
Автор

Thank you so much for this nice way to handle json ❤❤❤

Jamous
Автор

First of all thanks for the fantastic content you make! Can you please make a short video about the staff you use (like mic, cam, ...) to make your awesome videos?

alexandern
Автор

The linked Git repo points to a spring-boot-read-yaml project

FredrikRambris
Автор

How to handle the check if the key is present or not in the json node? If it is very nested, it would not be nice to check for null every step.

sudipta_samanta
Автор

I don't like Spring, but it seems that you want something like jsonPath...

luisdanielmesa
Автор

Or

@Test
void parseFile() throws JsonProcessingException {
var tree = objectMapper.readTree(json);
var posts =
.flatMap(n ->
.flatMap(n ->
.filter(JsonNode::isArray)
.map(Iterable::spliterator)
.map(s -> StreamSupport.stream(s, false))
.stream()
.flatMap(s -> s)
.map(n -> n.get("node"))
.map(n -> {
try {
return objectMapper.treeToValue(n, Post.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
})
.toList();


}

Post.class is a simple record of a post. The magic is treeToValue. Use traversing functions to get to the actual object and then use standard Jackson deserialization to your objects.

FredrikRambris