is it possible to upload a Map to Apache ISIS' restful interface? I have following interface where I want to upload to:
public SendMessageResponse send(
@ParameterLayout(named = "dummyParam1") @Parameter(optionality = Optionality.MANDATORY) String dummyParam1,
@ParameterLayout(named = "dummyParam2") @Parameter(optionality = Optionality.MANDATORY) String dummyParam2,
@ParameterLayout(named = "dummyMap1") @Parameter(optionality = Optionality.OPTIONAL) Map<String, String> dummyMap1)
{ ... }
dummyMap1
is the parameter I want to upload. In Java this is my try to convert a JavaMap to a JSON String:
Map<String, String> dummyMap1Up = new HashMap<String, String>();
dummyMap1Up.put("Test123", "123");
dummyMap1Up.put("Test456", "456");
JSONObject json = new JSONObject();
json.put("dummyParam1", "someString");
json.put("dummyParam2", "someOtherString");
json.put("dummyMap1", dummyMap1Up);
But when I want to upload this JSON all parameters are good, except the Map. I get a 422 Unprocessable Entity
status and the following error: Expected a link (because this object's type is not a value) but found no 'href'"
.
I tried to figure out how a Map is build in JSON in Apache ISIS. I tried to get a map from an Apache ISIS response, but the only thing I get is the notice that it is disabled because "disabledReason" : "Non-cloneable view models are read-only"
.
So my question is now: is it possible to upload a JavaMap to Apache ISIS using JSON representation, or is it impossible? When it is impossible to do so, is there any other good solution to upload the Map parts separately or someting like that?
Cheers and thanks for your answers!
The short answer is "no", the RO viewer does not support this, mostly because (currently at least) action parameters can only be scalars, not lists or maps.
You have a couple of choices.
The first is to serialize your map as a json string, and then just define the parameter as a string. Within the action you'll need to deserialize it, obviously.
Alternatively, you can always define additional custom endpoints outside of those provided by the RO viewer. For this you need to subclass RestfulObjectsApplication [1] to add your additional endpoints and then to register in web.xml [2]
HTH,
Dan
[1] https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/RestfulObjectsApplication.java#L36 [2] https://github.com/apache/isis/blob/master/example/application/simpleapp/webapp/src/main/webapp/WEB-INF/web.xml#L272