Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

geting null, but expected randon UUID

geting null, but expected randon UUID
entity

@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {

  private UUID userId;
  private String firstName;
  private String lastName;
  private Gender gender;
  private Integer age;
  private String email;

   public enum Gender {
        MALE, FEMALE
    }
}  

service method

public int insertUser(User user) {
        return repository.insertUser(UUID.randomUUID(), user);
    }  

repository method

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Override
public int insertUser(UUID userId, User user) {
    database.put(userId, user);
    return 1;
}  

controller

@PostMapping()
public ResponseEntity<Integer> insertNewUser(@RequestBody User user) {
    int result = service.insertUser(user);
    if (result == 1) {
        return ResponseEntity.ok().build();
    }
    return ResponseEntity.badRequest().build();
}    

after insert entity and getting, it has userId null
enter image description here

>Solution :

Try:

@Override
public int insertUser(UUID userId, User user) {
    user.setUserId(userId);
    database.put(userId, user);
    return 1;
}  
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading