3
Imagine that we are receiving a JSON via REST, so for those who use spring or jersey, usually use the Jackson that deserializes the json string for java object automatically, that at first I was impressed, but the short time I have been working with Nodejs, well the goal is not to compare, but rather to understand why in java can not be equal (which would be very good).
I learned that I need to create a DTO or VO (POJO), which represents the received json so that Jackson can deserialize and provide me with a ready-to-use JAVA object, but keep creating DTO after seeing the naturalness that this occurs with Nodejs, Poxa has made me very angry... because sometimes we receive "complex" json with various objects inside objects, inside arrays, etc...
The question is simple: Is there any way to receive a json and access its attributes without having to create Dtos?
Example:
{
"id": "1",
"nome": "TESTE",
"atividades": [
{
"id": "1",
"tarefa": "Fazer tal coisa"
}
]
}
Now I would like to access the attributes, in Node I would do something like this, detail without Dtos:
objeto.id
objeto.nome
Already in JAVA I would have to create a DTO for the parent object and another for the array, so that Jackson deserialize, this is a bag with all respect... a platform like JAVA surely must have something better, I believe that the problem here is myself that I do not know a way, all help is welcome.
Hello Lucas, Great explanation, thank you very much!! I think that for these and other reasons that Nodejs has been gaining a lot of space quickly, I notice a lot of naturalness in programming JS, of course it should have its negative points, but for now I don’t see many reasons to use JAVA in the day-day, multi-platform is no longer such a big advantage. I’m a fan of C++ and JAVA maybe someone brings some idea we don’t know yet. !!!
– Marcelo Ribeiro