In Spring Data REST 3.2.6.RELEASE, given an enum field annotated with org.springframework.data.rest.core.annotation.Description, in this example, gender
@Entity
@Data
@NoArgsConstructor
public class User {
@Id
Long id;
@Description("User name")
String name;
@Description("User gender, MALE or FEMALE")
Gender gender;
}
when get JSON schema, then NullPointerException.
- Run this Spring Boot application on localhost:8080
- Visit http://localhost:8080/profile/users with header "Accept: application/schema+json", for example
curl --request GET 'http://localhost:8080/profile/users' \ --header 'Accept: application/schema+json' \ --include
- Get HTTP 500 response
- Application log shows a NullPointerException thrown at PersistentEntityToJsonSchemaConverter.java:489
org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.JacksonProperty.getSchemaProperty(BeanPropertyDefinition, TypeInformation<?>, ResourceDescription, InternalMessageResolver)
At PersistentEntityToJsonSchemaConverter.java:489
description.getDefaultMessage().equals(resolvedDescription)
, the implementation class
AnnotationBasedResourceDescription
doesn't implement method getDefaultMessage()
and its super implementation
ResolvableResourceDescriptionSupport.getDefaultMessage()
return null
.
Put the description to rest-messages.properties, see https://docs.spring.io/spring-data/rest/docs/current/reference/html/#metadata.alps.descriptions
I might forget to update the description if put to an external file rest-messages.properties.
And spring-data-rest-tests
does demonstrates its usage.
Actually I found this annotation @Description
from @RepositoryRestResource.itemResourceDescription
.
Just try and the description is shown in ALPS document.