InvalidRequestException if I want to start a process vie REST API calls and use a 'ß' in a serialized linkedHashMap in a given variable

This is my JSON body for the call:
{
“variables” : {
“customerRequestId” : {
“type” : “String”,
“value” : “asd5”
},
“companyId” : {
“type” : “String”,
“value” : “asdf”
},
“address” : {
“valueInfo” : {
“objectTypeName” : “java.util.LinkedHashMap”,
“serializationDataFormat” : “application/json”
},
“value” : {
“country” : “IT”,
“city” : “Musterstadt”,
“addressType” : “BOX_ADDRESS”,
“street” : “Musterstraße”,
“houseNumber” : “12”,
“postcode” : “50667”,
“primaryAddress” : true
}
},
“customerRequestType” : {
“type” : “String”,
“value” : “changePartnerAddress”
},
“partnerId” : {
“type” : “String”,
“value” : “5043”
},
“userId” : {
“type” : “String”,
“value” : “88”
}
}
}
And this is my response code.
{
“type”: “InvalidRequestException”,
“message”: “”
}
This Problem only occurs if my street name is written with a ‘ß’. I haven’t tried it with ä, ö, ü but it will probably be the same.
How can I fix this?

Hi @cesei ,

I would say there is an issue when parsing the json body.

Could you please try to explicitly set the encoding for your request:

Content-Type: application/json; charset=utf-8

Kind regards
Adagatiya

1 Like

Also, don’t forget to actually use UTF-8 when converting the request to bytes (over the wire, just bytes are sent, not characters).

1 Like

I have tried what you told me and while it works with postmen, my code does not go through.
Here is my Code:

CloseableHttpClient httpClient = HttpClients.createDefault();
		LOGGER.info("HTTPClient wurde erfolgreich erzeugt.");
	    HttpPost httpPost = new HttpPost(baseURL + "process-definition/key/" + processDefinitionResult + "/start");
	    httpPost.setHeader("Accept", "application/json;charset=utf-8");
	    httpPost.addHeader("Content-Type", "application/json;charset=utf-8");

	    
		JSONObject json = new JSONObject();
		JSONObject last = new JSONObject();
		JSONObject companyIdJSON = new JSONObject();
		companyIdJSON.put("value", companyId);
		companyIdJSON.put("type", String.class.getSimpleName());
		json.put("companyId", companyIdJSON);

		JSONObject customerRequestTypeJSON = new JSONObject();
		customerRequestTypeJSON.put("value", customerRequestType);
		customerRequestTypeJSON.put("type", "String");
		json.put("customerRequestType", customerRequestTypeJSON);

		for (Map.Entry<?, ?> entry : rawDataMap.entrySet()) {
			JSONObject rawData = new JSONObject();
			if (entry.getValue() != null && !(entry.getValue() instanceof String)) {
				JSONObject valueInfo = new JSONObject();
				valueInfo.put("objectTypeName", entry.getValue().getClass().getName());
				valueInfo.put("serializationDataFormat", "application/x-java-serialized-object");
				rawData.put("value", entry.getValue());
				rawData.put("valueInfo", valueInfo);
			} else {
				rawData.put("value", entry.getValue());
				rawData.put("type", String.class.getSimpleName());
			}

			json.put(entry.getKey().toString(), rawData);
		}

		JSONObject customerRequestIdJSON = new JSONObject();
		customerRequestIdJSON.put("value", customerRequestId);
		customerRequestIdJSON.put("type", String.class.getSimpleName());
		json.put("customerRequestId", customerRequestIdJSON);

		last.put("variables", json);
	    

		StringEntity params = null;
		
		try {
			params = new StringEntity(last.toString());
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		httpPost.setEntity(params);
		try {
			httpClient.execute(httpPost);
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

I know the formating of the JSON is quite ugly but i havent found a better solution yet to construct it fitting the criteria of the documentation.
Do you see where the problem is?

Hi @cesei ,
instead of manually setting the content type, I encourage you to create the StringEntity as follows:

new StringEntity(last.toString(), ContentType.APPLICATION_JSON)

Then the framework will automatically assign the matching charset. If you omit this parameter (as you did), then it will use text/plain as content type with ISO-8859-1 encoding as per java docs. This mechanism has overriden the parameters you set beforehand.

Kind regards
Adagatiya

1 Like