package com.nitorcreations.puggly;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.nitorcreations.puggly.domain.tranforms.ExchangeTransform;

public class Transforms {

    public static ExchangeTransform prettyPrintJsonRequestBody() {
        return exchange -> {
            exchange.request.body = new GsonBuilder().setPrettyPrinting().create().toJson(new JsonParser().parse(exchange.request.body));
            return exchange;
        };
    }

    public static ExchangeTransform prettyPrintJsonResponseBody() {
        return exchange -> {
            exchange.response.body = new GsonBuilder().setPrettyPrinting().create().toJson(new JsonParser().parse(exchange.response.body));
            return exchange;
        };
    }

    public static ExchangeTransform replaceResponseBody(String replacement) {
        return exchange -> {
            exchange.response.body = replacement;
            return exchange;
        };
    }

    public static ExchangeTransform replaceRequestBody(String replacement) {
        return exchange -> {
            exchange.request.body = replacement;
            return exchange;
        };
    }

    protected Transforms() {
        // empty private constructor for util class
    }
}

@@ -29,16 +29,45 @@
 uggly;%0A%0A
+import com.google.gson.Gson;%0A
 import c
@@ -90,24 +90,24 @@
 sonBuilder;%0A
-
 import com.g
@@ -226,16 +226,106 @@
 orms %7B%0A%0A
+    private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();%0A    %0A
     publ
@@ -452,54 +452,12 @@
 y = 
-new GsonBuilder().setPrettyPrinting().create()
+gson
 .toJ
@@ -693,54 +693,12 @@
 y = 
-new GsonBuilder().setPrettyPrinting().create()
+gson
 .toJ

use a singleton Gson for some performance gains