Json a Object, using api rest

1

I'm doing a java program using api rest to connect and get data from the database.

For now I have the following classes: And the json corresponding to the information of the users are:

{
    "id": "1",
    "name": "ejemplo",
    "email": "[email protected]"
}

How can I pass the information of this user to the "User" type in order to access the corresponding methods getEmail() and getNombre() ?

    
asked by Einer 02.03.2018 в 12:28
source

2 answers

1

I do not know if there is a more "current" library on this, but I know Gson , that basically you should create your class Usuario

public class Usuario {
    public int id;
    public String name;
    public String email;
}

Create the methods get and set and where you get the json to do:

Usuario usuario = new Gson().fromJson(tu_json, Usuario.class);
    
answered by 02.03.2018 в 13:18
0

For these cases, the most ideal is to use Jackson , which is one of the most used.

    
answered by 02.03.2018 в 23:19