Home > Enterprise >  Passing new object through postman raw json body gives null values
Passing new object through postman raw json body gives null values

Time:11-02

Im trying to post a new object(Nuser) through postman using raw body json. The birthdate and insertion come through, but the first and lastname come as null value. I can't seem to find the problem by myself hence im asking it here. Postman Database

My baseuser class:

@Entity
public abstract class BaseUser {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int Id;

    private String FirstName;

    private String LastName;
    private String Insertion;
    private LocalDate Birthdate;

    public BaseUser() {
    }

    public BaseUser(String firstName, String lastName, String insertion, LocalDate birthdate) {
        FirstName = firstName;
        LastName = lastName;
        Insertion = insertion;
        Birthdate = birthdate;
    }

    public BaseUser(int id, String firstName, String lastName, String insertion, LocalDate birthdate) {
        Id = id;
        FirstName = firstName;
        LastName = lastName;
        Insertion = insertion;
        Birthdate = birthdate;
    }

My Nuser class

@Entity
public class Nuser extends BaseUser
{
    public Nuser(String firstName, String lastName, String insertion, LocalDate birthdate) {
        super(firstName, lastName, insertion, birthdate);
    }

    public Nuser() {

    }
}

The Nuser Controller

@RestController
@RequestMapping("/user")
public class NuserController {

    @Autowired
    private NuserService nuserService;

    @PostMapping("/add")
    public String add(@RequestBody Nuser nuser)
    {
        nuserService.AddUser(nuser);
        return "New account has been made";
    }

}

CodePudding user response:

firstname, firstName, and FirstName are all different identifiers. They need to match.

Note that following Java conventions will make your life much easier: The names of items that are not classes (variables, fields, methods) should start with lowercase letters. Additionally, following REST conventions will make your life easier: POST already means "add", so don't have an extra /add in the URL, just POST /user.

  • Related