|
12 | 12 | import static com.fasterxml.jackson.databind.node.JsonNodeType.OBJECT; |
13 | 13 | import com.fasterxml.jackson.databind.node.MissingNode; |
14 | 14 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 15 | +import com.fasterxml.jackson.databind.node.TextNode; |
15 | 16 | import io.clownfish.clownfish.jsonator.conditions.ConditionsWrapper; |
16 | 17 | import io.clownfish.clownfish.jsonator.conditions.ICondition; |
17 | 18 | import io.clownfish.clownfish.jsonator.datasource.DatasourceWrapper; |
@@ -122,7 +123,7 @@ public String map(String mappingcontent, boolean refresh) { |
122 | 123 | JsonNode value = getJsonNodeVal(mapping, result, mainNode, refresh); |
123 | 124 | jsonlists.put(mapping.getTag(), value); |
124 | 125 | } |
125 | | - case "string", "number", "boolean" -> { |
| 126 | + case "string", "number", "boolean", "json", "string/json" -> { |
126 | 127 | // Single Verarbeitung |
127 | 128 | if (mapping.getParent().isEmpty()) { |
128 | 129 | String value = getStringValAPI(mapping, result, mainNode, 0, refresh); |
@@ -197,9 +198,36 @@ public String map(String mappingcontent, boolean refresh) { |
197 | 198 | if (listNode.size()>0) { |
198 | 199 | ObjectNode listentry = (ObjectNode)listNode.get(i); |
199 | 200 | if (null != listentry) { |
200 | | - listentry.put(mapping.getTag(), jn.at(mapping.getContentfield())); |
201 | | - if (listentry.get(mapping.getTag()).isMissingNode()) { |
202 | | - listentry.put(mapping.getTag(), mapping.getNullval()); |
| 201 | + if (0==mapping.getContenttype().compareToIgnoreCase("string/json")) { |
| 202 | + String format = jn.at(mapping.getListcondition()).asText(); |
| 203 | + switch (format) { |
| 204 | + case "string" -> { |
| 205 | + listentry.put(mapping.getTag(), jn.at(mapping.getContentfield())); |
| 206 | + if (listentry.get(mapping.getTag()).isMissingNode()) { |
| 207 | + listentry.put(mapping.getTag(), mapping.getNullval()); |
| 208 | + } |
| 209 | + } |
| 210 | + case "json" -> { |
| 211 | + ObjectMapper mapper = new ObjectMapper(); |
| 212 | + // Schritt 1: Erstelle einen TextNode (simuliert deinen Ausgangszustand) |
| 213 | + TextNode inputTextNode = TextNode.valueOf(jn.at(mapping.getContentfield()).asText()); |
| 214 | + // --- Konvertierung --- |
| 215 | + // Schritt 2: Extrahiere den reinen String-Wert aus dem TextNode |
| 216 | + String extractedString = inputTextNode.asText(); |
| 217 | + // Schritt 3: Parse den extrahierten String mit dem ObjectMapper in einen neuen JsonNode |
| 218 | + JsonNode resultNode = mapper.readTree(extractedString); |
| 219 | + |
| 220 | + listentry.put(mapping.getTag(), resultNode); |
| 221 | + if (listentry.get(mapping.getTag()).isMissingNode()) { |
| 222 | + listentry.put(mapping.getTag(), mapping.getNullval()); |
| 223 | + } |
| 224 | + } |
| 225 | + } |
| 226 | + } else { |
| 227 | + listentry.put(mapping.getTag(), jn.at(mapping.getContentfield())); |
| 228 | + if (listentry.get(mapping.getTag()).isMissingNode()) { |
| 229 | + listentry.put(mapping.getTag(), mapping.getNullval()); |
| 230 | + } |
203 | 231 | } |
204 | 232 | listNode.set(i, listentry); |
205 | 233 | } else { |
|
0 commit comments