Created
June 27, 2021 16:03
-
-
Save Francisco-Castillo/a4a9c427e520fcbda93bc064cb6c8852 to your computer and use it in GitHub Desktop.
JSON Binding
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.
Learn more about bidirectional Unicode characters
{ | |
"text": "Respuesta en formato texto", | |
"observations":"Observaciones del administrador", | |
"creationDate": "2012-04-23T18:25", | |
"fileId":1, | |
"patientTestId":3 | |
} |
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.
Learn more about bidirectional Unicode characters
@Getter | |
@Setter | |
@NoArgsConstructor | |
@AllArgsConstructor | |
@ToString | |
public class ResponseDTO { | |
private Long responseId; | |
private String text; | |
private String observations; | |
private LocalDateTime creationDate; | |
private Long fileId; | |
private Long patientTestId; | |
} |
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.
Learn more about bidirectional Unicode characters
public ResponseEntity<Object> create(String model) { | |
try { | |
Jsonb jsonb = JsonbBuilder.create(); | |
// Capturamos objeto json y convertimos a objeto java | |
ResponseDTO responseDTO = jsonb.fromJson(model, ResponseDTO.class); | |
} catch (Exception e) { | |
// Tratar excepcion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fragmento de código que muestra como utilizar la API JSON-B para convertir objetos JSON en objetos Java