package com.tinkerpop.gremlin.structure.io.graphson;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.tinkerpop.gremlin.structure.Graph;

import java.io.IOException;

/**
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
class GraphSONGraph {
    private final Graph graphToSerialize;

    public GraphSONGraph(final Graph graphToSerialize) {
        this.graphToSerialize = graphToSerialize;
    }

    public Graph getGraphToSerialize() {
        return graphToSerialize;
    }

    static class GraphJacksonSerializer extends StdSerializer<GraphSONGraph> {
        public GraphJacksonSerializer() {
            super(GraphSONGraph.class);
        }

        @Override
        public void serialize(final GraphSONGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
                throws IOException, JsonGenerationException {
            final Graph g = graph.getGraphToSerialize();
            jsonGenerator.writeStartObject();

            if (g.getFeatures().graph().supportsMemory())
                jsonGenerator.writeObjectField(GraphSONModule.TOKEN_PROPERTIES, g.memory().asMap());

            jsonGenerator.writeArrayFieldStart(GraphSONModule.TOKEN_VERTICES);
            g.V().forEach(v -> {
                try {
                    jsonGenerator.writeObject(v);
                } catch (Exception ex) {
                    // todo: wish this would just throw
                }
            });
            jsonGenerator.writeEndArray();

            jsonGenerator.writeArrayFieldStart(GraphSONModule.TOKEN_EDGES);
            g.E().forEach(e -> {
                try {
                    jsonGenerator.writeObject(e);
                } catch (Exception ex) {
                    // todo: wish this would just throw
                }
            });
            jsonGenerator.writeEndArray();

            jsonGenerator.writeEndObject();
        }
    }
}

@@ -319,16 +319,74 @@
 e.Graph;
+%0Aimport com.tinkerpop.gremlin.util.function.FunctionUtils;
 %0A%0Aimport
@@ -1497,57 +1497,35 @@
 ach(
-v -%3E %7B%0A                try %7B%0A                    
+FunctionUtils.wrapConsumer(
 json
@@ -1525,33 +1525,34 @@
 er(jsonGenerator
-.
+::
 writeObject(v);%0A
@@ -1550,141 +1550,9 @@
 ject
-(v);%0A                %7D catch (Exception ex) %7B%0A                    // todo: wish this would just throw%0A                %7D%0A            %7D
+)
 );%0A 
@@ -1700,57 +1700,35 @@
 ach(
-e -%3E %7B%0A                try %7B%0A                    
+FunctionUtils.wrapConsumer(
 json
@@ -1728,33 +1728,34 @@
 er(jsonGenerator
-.
+::
 writeObject(e);%0A
@@ -1753,141 +1753,9 @@
 ject
-(e);%0A                %7D catch (Exception ex) %7B%0A                    // todo: wish this would just throw%0A                %7D%0A            %7D
+)
 );%0A 

Use the ThrowingConsumer in IO when writing to JSON.