ServiceCall<NotUsed, GetPersonResponse> getPerson(float id, float id2);
@Override
default Descriptor descriptor() {
return named("getPerson")
.withCalls(restCall(GET, "/getPerson/id/:id/id2/:id2", this::getPerson))
.withPathParamSerializer(Float.class,
PathParamSerializers.required("Float", String::parseFloat, Object::toString))
.withAutoAcl(true);
}
This can then be called with the URL http://localhost:9000/getPerson/id/1.23/id2/4.56.ServiceCall<NotUsed, GetPersonResponse> getPerson(IdHolder ids);
@Override
default Descriptor descriptor() {
return named("getPerson")
.withCalls(restCall(GET, "/getPerson/:ids", this::getPerson))
.withPathParamSerializer(
IdHolder.class,
PathParamSerializers.required(
"IdHolder", idHolderString -> {
String[] splitIds = idHolderString.split(",");
if (splitIds.length != 2) {
throw new IllegalArgumentException(
"Expected two ids but got " + splitIds.length + " in " + idHolderString);
}
return new IdHolder(
Float.parseFloat(splitIds[0]), // id
Float.parseFloat(splitIds[1]) // id2
);
},
ids -> ids.getId() + "," + ids.getId2()
)
)
.withAutoAcl(true);
}
This can then be called with the URL http://localhost:9000/getPerson/1.23,4.56.
The custom path parameter serializer takes care of converting back and forth between the Ids and a comma-separated string. The example uses lambdas for brevity, but you might prefer to add methods to the class itself, even adding any custom validation that could be needed.*
If you do end up implementing a primitive's serializer using the aforementioned interface then we are always open to integrating it for other users as part of a project contribution. Alternatively, you could provide us with the code so that we can push it through ourselves.