DATACOUCH-604 - Fix NPE when looking for Id field in interface.

This was failing with a repository for the domain object CouchbaseOAuth2AccessToken.
The following dependency is needed.

        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.4.1.RELEASE</version>
        </dependency>

package org.springframework.data.couchbase.domain;

import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;

@Document(expiry = 30 * 24 * 60 * 60)
public class CouchbaseOAuth2AccessToken extends DefaultOAuth2AccessToken {

	private static final long serialVersionUID = 6537949925775752989L;

	@Id
	private String tokenId;

	@Field
	private String authentication;

	@Field
	private String authenticationKey;

	@Field
	private String clientId;

	@Field
	private String userName;

	// getters and setters omitted for brevity

	private CouchbaseOAuth2AccessToken() {
		this((String) null);
	}

	public CouchbaseOAuth2AccessToken(OAuth2AccessToken accessToken) {
		super(accessToken);
		this.tokenId = accessToken.getValue();
	}

	public CouchbaseOAuth2AccessToken(String value) {
		super(value);
		this.tokenId = value;
	}

}
This commit is contained in:
mikereiche
2020-09-14 16:57:00 -07:00
parent 07c28fe7fe
commit 4a52268f19

View File

@@ -16,7 +16,6 @@
package org.springframework.data.couchbase.core.mapping;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
@@ -28,8 +27,6 @@ import org.springframework.util.StringUtils;
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Locale;
/**
* Implements annotated property representations of a given {@link Field} instance.
* <p/>
@@ -99,7 +96,13 @@ public class BasicCouchbasePersistentProperty extends AnnotationBasedPersistentP
// DATACOUCH-145: allows SDK's @Id annotation to be used
@Override
public boolean isIdProperty() {
return isAnnotationPresent(Id.class) || super.isIdProperty()
|| this.getFieldName().toLowerCase(Locale.ROOT).equals("id");
if (super.isIdProperty()){
return true;
}
// is field named "id"
if(getName().equals("id")){
return true;
}
return false;
}
}