mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 05:30:43 +00:00
Avoid exceptions from jackson serialization of processValues that contain a map with a null key
This commit is contained in:
@ -655,4 +655,28 @@ class QJavalinProcessHandlerTest extends QJavalinTestBase
|
||||
assertEquals(200, response.getStatus());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** test running a process who has a value with a null key.
|
||||
*
|
||||
** This was a regression - that threw an exception from jackson at one point in time.
|
||||
**
|
||||
** Note: ported to v1
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_processPutsNullKeyInMap()
|
||||
{
|
||||
HttpResponse<String> response = Unirest.get(BASE_URL + "/processes/" + TestUtils.PROCESS_NAME_PUTS_NULL_KEY_IN_MAP + "/init").asString();
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
assertNotNull(jsonObject);
|
||||
JSONObject values = jsonObject.getJSONObject("values");
|
||||
JSONObject mapWithNullKey = values.getJSONObject("mapWithNullKey");
|
||||
assertTrue(mapWithNullKey.has("")); // null key currently set to become empty-string key...
|
||||
assertEquals("hadNullKey", mapWithNullKey.getString(""));
|
||||
assertTrue(mapWithNullKey.has("one"));
|
||||
assertEquals("1", mapWithNullKey.getString("one"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.javalin;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@ -53,6 +54,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.authentication.QAuthenticationMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReferenceLambda;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
|
||||
@ -112,6 +114,8 @@ public class TestUtils
|
||||
public static final String PROCESS_NAME_SIMPLE_THROW = "simpleThrow";
|
||||
public static final String PROCESS_NAME_SLEEP_INTERACTIVE = "sleepInteractive";
|
||||
|
||||
public static final String PROCESS_NAME_PUTS_NULL_KEY_IN_MAP = "putsNullKeyInMap";
|
||||
|
||||
public static final String STEP_NAME_SLEEPER = "sleeper";
|
||||
public static final String STEP_NAME_THROWER = "thrower";
|
||||
|
||||
@ -177,6 +181,7 @@ public class TestUtils
|
||||
qInstance.addProcess(defineProcessGreetPeopleInteractive());
|
||||
qInstance.addProcess(defineProcessSimpleSleep());
|
||||
qInstance.addProcess(defineProcessScreenThenSleep());
|
||||
qInstance.addProcess(defineProcessPutsNullKeyInMap());
|
||||
qInstance.addProcess(defineProcessSimpleThrow());
|
||||
qInstance.addReport(definePersonsReport());
|
||||
qInstance.addPossibleValueSource(definePossibleValueSourcePerson());
|
||||
@ -554,6 +559,26 @@ public class TestUtils
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Define an interactive version of the 'greet people' process
|
||||
*******************************************************************************/
|
||||
private static QProcessMetaData defineProcessPutsNullKeyInMap()
|
||||
{
|
||||
return new QProcessMetaData()
|
||||
.withName(PROCESS_NAME_PUTS_NULL_KEY_IN_MAP)
|
||||
.withTableName(TABLE_NAME_PERSON)
|
||||
.withStep(new QBackendStepMetaData().withName("step")
|
||||
.withCode(new QCodeReferenceLambda<BackendStep>((runBackendStepInput, runBackendStepOutput) ->
|
||||
{
|
||||
HashMap<String, String> mapWithNullKey = new HashMap<>();
|
||||
mapWithNullKey.put(null, "hadNullKey");
|
||||
mapWithNullKey.put("one", "1");
|
||||
runBackendStepOutput.addValue("mapWithNullKey", mapWithNullKey);
|
||||
})));
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Define a process with just one step that sleeps and then throws
|
||||
*******************************************************************************/
|
||||
|
@ -216,4 +216,26 @@ class ProcessInitSpecV1Test extends SpecTestBase
|
||||
// todo - in a higher-level test, resume test_processInitGoingAsync at the // request job status before sleep is done // line
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testProcessPutsNullKeyInMap()
|
||||
{
|
||||
HttpResponse<String> response = Unirest.post(getBaseUrlAndPath() + "/processes/" + TestUtils.PROCESS_NAME_PUTS_NULL_KEY_IN_MAP + "/init")
|
||||
.multiPartContent()
|
||||
.asString();
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
|
||||
|
||||
JSONObject values = jsonObject.getJSONObject("values");
|
||||
JSONObject mapWithNullKey = values.getJSONObject("mapWithNullKey");
|
||||
assertTrue(mapWithNullKey.has("")); // null key currently set to become empty-string key...
|
||||
assertEquals("hadNullKey", mapWithNullKey.getString(""));
|
||||
assertTrue(mapWithNullKey.has("one"));
|
||||
assertEquals("1", mapWithNullKey.getString("one"));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user