paulcwarren/spring-content

Allow overriding name of content field in multipart payload

rschev opened this issue · 0 comments

Is your feature request related to a problem? Please describe.
I can override how a content field is referred to in the url via @RestResource(path = "..."), but when using the feature to create an entity+content in a single request, I have to use the name of the java field, and I don't seem to have a way to override this. For other fields on the entity that I send in this multipart request, an @JsonProperty(value = "...") on the field suffices, but not for content fields.

Describe the solution you'd like
I'd like for @RestResource to get a new parameter that lets me override this, for instance:

@RestResource(linkRel = "d:attached_document", path = "attached-document", fieldName = "attached_document")

Describe alternatives you've considered

Additional context
In the below code sample, when I send a multipart request to create an Invoice, I have to refer to the content fields as attachedDocument and qrCode, it would be nice to have a way to refer to them as attached_document and qr_code.

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

	@ContentId
	@JsonIgnore
	@RestResource(linkRel = "d:attached_document", path = "attached-document")
	private String attachedDocumentId;

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

	@MimeType
	@JsonProperty("attached_document_mimetype")
	private String attachedDocumentMimetype;

	@OriginalFileName
	@JsonProperty("attached_document_filename")
	private String attachedDocumentFilename;

	@Embedded
	@AttributeOverride(name = "id", column = @Column(name = "qr_code__id"))
	@AttributeOverride(name = "length", column = @Column(name = "qr_code__length"))
	@AttributeOverride(name = "mimetype", column = @Column(name = "qr_code__mimetype"))
	@AttributeOverride(name = "filename", column = @Column(name = "qr_code__filename"))
	@RestResource(linkRel = "d:qr_code", path = "qr-code")
	@JsonProperty(value = "qr_code")
	private Content qrCode;
}

@Embeddable
@Getter
@Setter
public class Content {
	@ContentId
	@JsonIgnore
	private String id;

	@ContentLength
	@JsonProperty(access = Access.READ_ONLY)
	private Long length;

	@MimeType
	private String mimetype;

	@OriginalFileName
	private String filename;
}