0

When the entity classes were first created they were modeled in JPA to match database field names. For our rest endpoints we used JsonProperty to let Jackson auto map names the client would expect they are kabob case. However we are now implementing search functionality and are building it using QueryDSL. It works and works well as long as we use the internal field names.

What we are looking to do though is accept querystrings with the JsonProperty Name.

Like: campaign-grouping-code=123 vs groupingCode=123

I am assuming it would probably have to be done in the Q Classes that are generated but can't find much documentation on them.

@Column(name = "GROUPING_CODE")
private String groupingCode;

@JsonProperty("campaign-grouping-code")
@NotBlank(message = "1", groups = CampaignFieldCheck.class)
@Size(max = 40, message = "100", groups = CampaignFieldCheck.class)
public String getGroupingCode() {
    return groupingCode;
}

public void setGroupingCode(String groupingCode) {
    this.groupingCode = groupingCode;
}
dstigue
  • 31
  • 10

2 Answers2

0

Quite simply: no that is not possible because the Spring Data endpoints use the values from the attributes in the metamodel, which in the case for querydsl-jpa are always the JPA attribute names, which are in turn derived from the field names, and - is not a valid character in a Java field name.

  • I was hoping that wasn't the case. I think what I will be doing is renaming the internal field names to be like the external camel cased instead of kabob. – dstigue May 03 '21 at 13:13
0

So there isnt a way to get the jsonproperty names to work. There is a workaround aliasing.. In this link you can find the black list and white list settings. Aliases are automatically white listed. but the aliases can be mapped via whatever text string makes sense to the field names.

https://gt-tech.bitbucket.io/spring-data-querydsl-value-operators/README.html

dstigue
  • 31
  • 10