Skip to content

Commit

Permalink
Serialize the JSON node only if there is content
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Radischat committed Sep 5, 2016
1 parent 2a314df commit 00d9b98
Showing 1 changed file with 10 additions and 3 deletions.
@@ -1,7 +1,9 @@
package org.opentripplanner.graph_builder.module;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.routing.graph.Graph;

Expand All @@ -26,10 +28,9 @@ public EmbedConfig(JsonNode builderConfig, JsonNode routerConfig) {

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
ObjectMapper mapper = new ObjectMapper();
try {
graph.builderConfig = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(builderConfig);
graph.routerConfig = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(routerConfig);
graph.builderConfig = serializedConfiguration(builderConfig);
graph.routerConfig = serializedConfiguration(routerConfig);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand All @@ -40,4 +41,10 @@ public void checkInputs() {

}

private String serializedConfiguration(JsonNode config) throws JsonProcessingException{
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
return config.isMissingNode() ? null : writer.writeValueAsString(config);
}

}

0 comments on commit 00d9b98

Please sign in to comment.