Skip to content

Commit

Permalink
Merge pull request #10 from GDLMadushanka/json
Browse files Browse the repository at this point in the history
Handle null values in JSON to CSV conversion.
  • Loading branch information
GDLMadushanka authored Dec 21, 2021
2 parents 98bd092 + dd9ccbb commit aae00e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.module</groupId>
<artifactId>mediation-csv-module</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<packaging>jar</packaging>
<name>WSO2 Carbon - Connector For csvConnector</name>
<url>http://wso2.org</url>
Expand Down Expand Up @@ -265,7 +265,7 @@
<goal>attached</goal>
</goals>
<configuration>
<finalName>${connector.name}-connector-1.0.1</finalName>
<finalName>${connector.name}-connector-1.0.3</finalName>
<appendAssemblyId>false</appendAssemblyId>
<filters>
<filter>src/main/assembly/filter.properties</filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.module.core.SimpleMediator;
Expand Down Expand Up @@ -48,7 +49,11 @@ public void mediate(SimpleMessageContext mc) {
List<String> csvEntry = new ArrayList<>();
Set<Map.Entry<String, JsonElement>> entries = obj.entrySet();
for (Map.Entry<String, JsonElement> elementEntry : entries) {
csvEntry.add(elementEntry.getValue().getAsString());
if (elementEntry.getValue() instanceof JsonNull) {
csvEntry.add("");
} else {
csvEntry.add(elementEntry.getValue().getAsString());
}
}

return csvEntry.toArray(new String[]{});
Expand Down

0 comments on commit aae00e9

Please sign in to comment.