paulcwarren/spring-content

Link relation and path configured with @RestResource ignored for content properties with multiple capital letters

vierbergenlars opened this issue · 1 comments

Describe the bug

This looks like a similar bug as #1146, except now applied to to RestResourceMappingBuilder instead of ContentPropertyMappingContextVisitor.

To Reproduce

Given a JPA entity with a @RestResource annotation:

@Entity
@NoArgsConstructor
@Getter
@Setter
public class Person {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@JsonProperty(access = JsonProperty.Access.READ_ONLY)
	private UUID id;

	private String name;

	@RestResource(linkRel = "d:mugshot")
	@ContentId
	@JsonIgnore
	private String mugshotId;

	@ContentLength
	@JsonProperty(access = JsonProperty.Access.READ_ONLY, value = "mugshot_length")
	private Long mugshotLength;

	@MimeType
	@JsonProperty("mugshot_mimetype")
	private String mugshotMimetype;

	@OriginalFileName
	@JsonProperty("mugshot_filename")
	private String mugshotFilename;

	@RestResource(linkRel = "d:idcard_front", path = "idcard-front")
	@ContentId
	@JsonIgnore
	private String idcardFrontId;

	@ContentLength
	@JsonProperty(access = JsonProperty.Access.READ_ONLY, value = "idcard_front_length")
	private Long idcardFrontLength;

	@MimeType
	@JsonProperty("idcard_front_mimetype")
	private String idcardFrontMimetype;

	@OriginalFileName
	@JsonProperty("idcard_front_filename")
	private String idcardFrontFilename;

	@RestResource(linkRel = "d:idcard_back", path = "idcard-back")
	@ContentId
	@JsonIgnore
	private String idcardBackId;

	@ContentLength
	@JsonProperty(access = JsonProperty.Access.READ_ONLY, value = "idcard_back_length")
	private Long idcardBackLength;

	@MimeType
	@JsonProperty("idcard_back_mimetype")
	private String idcardBackMimetype;

	@OriginalFileName
	@JsonProperty("idcard_back_filename")
	private String idcardBackFilename;
}

Steps to reproduce the behavior:

  1. Create a spring-content application with this entity
  2. Create a new Person instance with POST /persons with an empty object
  3. Notice that in the returned JSON, the link relation and path as specified in @RestResource is not taken into account, it falls back to the default instead. (Note that the annotation does take effect for the "mugshot" content property

Expected behavior

Of course, I expect the settings set in the @RestResource annotations to take effect

Screenshots

{
  "id": "8f8739ba-480b-4c69-bba0-ffb7fdbfa03b",
  "name": "wwcxcs",
  "mugshot_length": null,
  "mugshot_mimetype": null,
  "mugshot_filename": null,
  "idcard_front_length": null,
  "idcard_front_mimetype": null,
  "idcard_front_filename": null,
  "idcard_back_length": null,
  "idcard_back_mimetype": null,
  "idcard_back_filename": null,
  "_links": {
    "self": {
      "href": "http://localhost:8886/persons/8f8739ba-480b-4c69-bba0-ffb7fdbfa03b"
    },
    "d:person": {
      "href": "http://localhost:8886/persons/8f8739ba-480b-4c69-bba0-ffb7fdbfa03b"
    },
    "d:mugshot": {
      "href": "http://localhost:8886/persons/8f8739ba-480b-4c69-bba0-ffb7fdbfa03b/mugshot"
    },
    "idcardBack": {
      "href": "http://localhost:8886/persons/8f8739ba-480b-4c69-bba0-ffb7fdbfa03b/idcardBack"
    },
    "idcardFront": {
      "href": "http://localhost:8886/persons/8f8739ba-480b-4c69-bba0-ffb7fdbfa03b/idcardFront"
    }
  }
}

If applicable, add screenshots to help explain your problem.

Additional context

I believe the fix is to use the same function used in ContentPropertyMappingContextVisitor in RestResourceMappingBuilder.

Fixed in #1573