I am trying to migrate some spring-webflux
sample codes to kotlin.
Currently I want to convert my Spring Data Mongo sample to kotlin. There is a User
, the original Data Mongo version looks:
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document
class User implements UserDetails {
@Id
private String id;
private String username;
private String password;
@Builder.Default()
private boolean active = true;
@Builder.Default()
private List<String> roles = new ArrayList<>();
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return AuthorityUtils.createAuthorityList(roles.toArray(new String[roles.size()]));
}
@Override
public boolean isAccountNonExpired() {
return active;
}
@Override
public boolean isAccountNonLocked() {
return active;
}
@Override
public boolean isCredentialsNonExpired() {
return active;
}
@Override
public boolean isEnabled() {
return active;
}
}
The UserDetails
interface includes some getXXX and isXXX methods, how to add override
to the username
and password
proerpties in kotlin?
BTW: Currently I removed UserDetails
in the kotlin version, check here:
@Document
data class User(
@Id var id: String? = null,
var username: String? = null,
var password: String? = null,
var active: Boolean = true,
var roles: List<String> = ArrayList()
)
UPDATE:How to add the , this question is helpful.UserDetails
interface to it?
The new problem is when use destruction, it does not work.
(id, username, password, active, roles) = <a user>
The User
is located https://github.com/hantsy/spring-reactive-sample/blob/master/kotlin-gradle/src/main/kotlin/com/example/demo/User.kt . Currently I commented out the version implemented UserDetails
. If I use the commented codes(User:UserDetails), the desstruction
codes in Beans.kt
will report errors in IDE. The errors occur on username
and password
: destructing declaration initializer of type User! must have a component2 function.