### Question:
PayloadMapper { public JsonObject visitAndMap(final Collection<ParameterMeta> parameters, final Map<String, String> payload) { return unflatten("", ofNullable(parameters).orElseGet(Collections::emptyList), payload == null ? emptyMap() : payload); }  JsonObject visitAndMap(final Collection<ParameterMeta> parameters, final Map<String, String> payload);  }### Answer:
@Test void simpleDirectValue() throws NoSuchMethodException { final List<ParameterMeta> params = service .buildParameterMetas(MethodsHolder.class.getMethod("primitives", String.class, String.class, int.class), "def", new BaseParameterEnricher.Context(new LocalConfigurationService(emptyList(), "test"))); final Map<String, String> payload = new HashMap<>(); payload.put("url", "http: final JsonValue value = extractorFactory.visitAndMap(params, payload); assertEquals("{\"url\":\"http: }
@Test void simpleListValue() throws NoSuchMethodException { final List<ParameterMeta> params = service .buildParameterMetas(MethodsHolder.class.getMethod("collections", List.class, List.class, Map.class), "def", new BaseParameterEnricher.Context(new LocalConfigurationService(emptyList(), "test"))); final Map<String, String> payload = new HashMap<>(); payload.put("ports[0]", "1"); payload.put("ports[1]", "2"); final JsonValue value = extractorFactory.visitAndMap(params, payload); assertEquals("{\"ports\":[1,2]}", value.toString()); }
@Test void complex() throws NoSuchMethodException { final List<ParameterMeta> params = service .buildParameterMetas(Model.class.getConstructor(Complex.class), "def", new BaseParameterEnricher.Context(new LocalConfigurationService(emptyList(), "test"))); final Map<String, String> payload = new TreeMap<>(); payload.put("configuration.objects[0].simple", "s"); payload.put("configuration.objects[0].otherObjects[0].value", "o11"); payload.put("configuration.objects[0].otherObjects[1].value", "o12"); payload.put("configuration.objects[1].otherObjects[0].value", "o21"); payload.put("configuration.objects[2].strings[0]", "s1"); payload.put("configuration.objects[2].strings[1]", "s2"); payload.put("configuration.simple", "rs"); payload.put("configuration.strings[0]", "rs1"); payload.put("configuration.other.value", "done"); final JsonValue value = extractorFactory.visitAndMap(params, payload); assertEquals("{\"configuration\":{\"objects\":[{\"otherObjects\":[{\"value\":\"o11\"},{\"value\":\"o12\"}]," + "\"simple\":\"s\"},{\"otherObjects\":[{\"value\":\"o21\"}]},{\"strings\":[\"s1\",\"s2\"]}]," + "\"other\":{\"value\":\"done\"},\"simple\":\"rs\",\"strings\":[\"rs1\"]}}", value.toString()); }