package com.msgilligan.bitcoinj.json.conversion;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.bitcoinj.core.Transaction;

import java.io.IOException;
import java.util.Formatter;

/**
 *
 */
public class TransactionHexSerializer extends JsonSerializer<Transaction> {
    @Override
    public void serialize(Transaction value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
        // From: http://bitcoin.stackexchange.com/questions/8475/how-to-get-hex-string-from-transaction-in-bitcoinj
        final StringBuilder sb = new StringBuilder();
        Formatter formatter = new Formatter(sb);
        byte[] bytes = value.bitcoinSerialize();
        for (byte b : bytes) {
            formatter.format("%02x", b);
        }
        formatter.close();
        gen.writeString(sb.toString());
    }
}

@@ -602,24 +602,96 @@
 ption %7B%0A    
+    gen.writeString(bytesToHexString(value.bitcoinSerialize()));%0A    %7D%0A%0A
     // From:
@@ -790,16 +790,74 @@
 itcoinj%0A
+    public static String bytesToHexString(byte%5B%5D bytes) %7B%0A
         
@@ -955,57 +955,8 @@
 b);%0A
-        byte%5B%5D bytes = value.bitcoinSerialize();%0A
     
@@ -1068,32 +1068,23 @@
         
-gen.writeString(
+return 
 sb.toStr
@@ -1088,17 +1088,16 @@
 String()
-)
 ;%0A    %7D%0A

Split out bytesToHexString as a static method.