spring-projects / spring-projects/spring-data-rest

NPE when get json schema from enum field with @Description [DATAREST-1508]

Open
#1,866 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
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

  1. AnnotationBasedResourceDescription forgot to override method getDefaultMessage(), while super.getDefaultMessage() return null.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.