I want to Serialize this body with Jackson.
but the "requestName" part will be different in many API Calls.
so I have some different objects for this part.
The problem is I want to parameterize the name of this JsonProperty but the Annotation doesnt accept the variable.
I get this error when I compile it :
/home/duma/IdeaProjects/API Testing/src/test/java/SingleRequest.java:16:19
java: element value must be a constant expression
Any Idea about this ?
body :
"singleRequest": {
"requestName": {
"canReplaceSpellCheckerQuery": false,
"language": "fa",
"query": "test",
"scope": "app",
"entities": ""
}
}
code :
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
public class SingleRequest {
private Object object;
@JsonIgnore
private String requestName;
SingleRequest(Object request, String requestName){
this.object = request;
this.requestName = requestName;
}
@JsonProperty(value = requestName)
public Object getObject() {
return object;
}
public void setObject(Object object) {
this.object = object;
}
public String getRequestName() {
return requestName;
}
public void setRequestName(String requestName) {
this.requestName = requestName;
}
}