spring-projects / spring-projects/spring-data-rest
NPE when get json schema from enum field with @Description [DATAREST-1508]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
yejianfengblue opened DATAREST-1508 and commented
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,
curl --request GET 'http://localhost:8080/profile/users' \
--header 'Accept: application/schema+json' \
--include
then NullPointerException thrown at PersistentEntityToJsonSchemaConverter.java:489.
I guess the cause might be
- AnnotationBasedResourceDescription forgot to override method getDefaultMessage(), while super.getDefaultMessage() return null.
- PersistentEntityToJsonSchemaConverter.java:489 should not call getDefaultMessage().
A demo Spring Data REST application is provided in github see the reference URL.
The workaround is put the description to rest-messages.properties as mentioned at https://docs.spring.io/spring-data/rest/docs/current/reference/html/#metadata.alps.descriptions
Is the use of @Description not recommanded? Because the description in @Description is shown in ALPS document only, while the description in rest-messages.properties is shown in both ALPS and JSON schema.
Affects: 3.2.6 (Moore SR6)
Reference URL: https://github.com/yejianfengblue/spring-data-rest-enum-description-npe
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.