Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ca.qhrtech.entities; import ca.qhrtech.utilities.LocalDateTimeDeserializer; import ca.qhrtech.utilities.LocalDateTimeSerializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.io.Serializable; import java.time.LocalDateTime; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import org.jsondoc.core.annotation.ApiObject; import org.jsondoc.core.annotation.ApiObjectField; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; /** * * @author bryan.bergen */ @Entity @ApiObject public class BGLUser implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @ApiObjectField(description = "A user's unique identifier") private long id; @ApiObjectField(description = "A user's chosen username") private String username; @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @ApiObjectField(description = "A user's hashed and salted password") private String password; @ApiObjectField(description = "Path to the user's avatar on the server") private String avatarPath; @ApiObjectField(description = "A user's email address") private String email; @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) @ApiObjectField(description = "The date the user signed up for BGL") private LocalDateTime joinDate; public BGLUser() { } public BGLUser(String username, String avatarPath, String email, String password) { //Testing constructor, will be removed in production this.username = username; this.avatarPath = avatarPath; this.email = email; this.joinDate = LocalDateTime.now(); this.password = new BCryptPasswordEncoder().encode(password); } public BGLUser(BGLUser user) { this.id = user.id; this.username = user.getUsername(); this.avatarPath = user.getAvatarPath(); this.email = user.getEmail(); } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getAvatarPath() { return avatarPath; } public void setAvatarPath(String avatarPath) { this.avatarPath = avatarPath; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public LocalDateTime getJoinDate() { return joinDate; } public void setJoinDate(LocalDateTime joinDate) { this.joinDate = joinDate; } @JsonIgnore public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }