package com.itranswarp.bitcoin.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JsonUtils {

	public static String toJson(Object o) {
		ObjectMapper mapper = new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
				.enable(SerializationFeature.INDENT_OUTPUT);
		try {
			return mapper.writeValueAsString(o);
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	}

	public static void printJson(Object o) {
		System.out.println(toJson(o));
	}

	public static <T> T fromJson(Class<T> clazz, String s) {
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		try {
			return mapper.readValue(s, clazz);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

}

@@ -58,16 +58,67 @@
 ception;
+%0Aimport java.io.InputStream;%0Aimport java.io.Reader;
 %0A%0Aimport
@@ -376,63 +376,55 @@
 %7B%0A%0A%09
-public static String toJson(Object o) %7B%0A%09%09ObjectMapper 
+static final ObjectMapper mapper;%0A%0A%09static %7B%0A%09%09
 mapp
@@ -446,16 +446,26 @@
 Mapper()
+;%0A%09%09mapper
 .disable
@@ -510,13 +510,18 @@
 ANS)
+;
 %0A%09%09
-%09%09
+mapper
 .ena
@@ -561,16 +561,130 @@
 UTPUT);%0A
+%09%09mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);%0A%09%7D%0A%0A%09public static String toJson(Object o) %7B%0A
 %09%09try %7B%0A
@@ -948,127 +948,365 @@
 %7B%0A%09%09
-ObjectMapper mapper = new ObjectMapper();%0A%09%09mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+try %7B%0A%09%09%09return mapper.readValue(s, clazz);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D%0A%09%7D%0A%0A%09public static %3CT%3E T fromJson(Class%3CT%3E clazz, InputStream in) %7B%0A%09%09try %7B%0A%09%09%09return mapper.readValue(in, clazz);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D%0A%09%7D%0A%0A%09public static %3CT%3E T fromJson(Class%3CT%3E clazz, Reader reader) %7B
 %0A%09%09t
@@ -1329,33 +1329,38 @@
 apper.readValue(
-s
+reader
 , clazz);%0A%09%09%7D ca

add json utils