// Path: src/main/java/dk/clanie/bitcoin/json/JsonExtra.java
// @SuppressWarnings("serial")
// @RooJavaBean(settersByDefault = false)
// public abstract class JsonExtra extends BaseClass {
// 
// 	private Map<String, Object> otherFields = newHashMap();
// 
// 	/**
// 	 * Sets name and value of other (unknown) JSON fields.
// 	 * 
// 	 * @param field
// 	 * @param value
// 	 */
// 	@JsonAnySetter
// 	@SuppressWarnings("unused") // Is used by Jackson
// 	private void set(String field, Object value)  {
// 		otherFields.put(field, value);
// 	}
// 
// 
// 	/**
// 	 * Gets names and values of all other (unknown) JSON fields.
// 	 * 
// 	 * @return Names and values of other fields available. 
// 	 */
// 	@JsonAnyGetter
// 	public Map<String, Object> getOtherFields() {
// 		return Collections.unmodifiableMap(otherFields);
// 	}
// 
// 
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import dk.clanie.bitcoin.json.JsonExtra;
import dk.clanie.io.IOUtil;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


	/**
	 * Perform serialization roundtrip testing of the given file.
	 * 
	 * @param file
	 *            - file with sample data in json format. The file name must
	 *            follow a fixed format including the respons class name - see
	 *            {@link #extractResponseClassName(File)}.
	 * @throws Exception
	 */
	private void doSerializationRoundtrip(File file) throws Exception {
		
		log.debug("Testing deserialization of sample file " + file.getName() + ".");

		String className = extractResponseClassName(file);
		String jsonSample = IOUtils.toString(file.toURI());
		@SuppressWarnings("unchecked")
		Class<? extends BitcoindJsonRpcResponse<?>> responseType = (Class<? extends BitcoindJsonRpcResponse<?>>) Class.forName("dk.clanie.bitcoin.client.response." + className);

		// Deserialize and re-serialize
		log.debug("Deserializing " + jsonSample);
		BitcoindJsonRpcResponse<?> response = objectMapper.readValue(jsonSample, responseType);
		String roundtrippedJson = objectMapper.writeValueAsString(response);
		assertThat("json -> obj -> json roundtrip serialization failed for " + file.getName() + ".", roundtrippedJson, equalTo(jsonSample));

		// Check that all fields are explicitly mapped.
		assertThat("Some fields in response not explicitly mapped (see otherFields): " + response.toString(), response.getOtherFields().size(), equalTo(0));
		
		Object resultObject = response.getResult();
// Path: src/main/java/dk/clanie/bitcoin/json/JsonExtra.java
// @SuppressWarnings("serial")
// @RooJavaBean(settersByDefault = false)
// public abstract class JsonExtra extends BaseClass {
// 
// 	private Map<String, Object> otherFields = newHashMap();
// 
// 	/**
// 	 * Sets name and value of other (unknown) JSON fields.
// 	 * 
// 	 * @param field
// 	 * @param value
// 	 */
// 	@JsonAnySetter
// 	@SuppressWarnings("unused") // Is used by Jackson
// 	private void set(String field, Object value)  {
// 		otherFields.put(field, value);
// 	}
// 
// 
// 	/**
// 	 * Gets names and values of all other (unknown) JSON fields.
// 	 * 
// 	 * @return Names and values of other fields available. 
// 	 */
// 	@JsonAnyGetter
// 	public Map<String, Object> getOtherFields() {
// 		return Collections.unmodifiableMap(otherFields);
// 	}
// 
// 
// }


// Path: src/test/java/dk/clanie/bitcoin/client/response/ResponseSerializationTest.java
import com.fasterxml.jackson.databind.ObjectMapper;
import dk.clanie.bitcoin.json.JsonExtra;
import dk.clanie.io.IOUtil;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



	/**
	 * Perform serialization roundtrip testing of the given file.
	 * 
	 * @param file
	 *            - file with sample data in json format. The file name must
	 *            follow a fixed format including the respons class name - see
	 *            {@link #extractResponseClassName(File)}.
	 * @throws Exception
	 */
	private void doSerializationRoundtrip(File file) throws Exception {
		
		log.debug("Testing deserialization of sample file " + file.getName() + ".");

		String className = extractResponseClassName(file);
		String jsonSample = IOUtils.toString(file.toURI());
		@SuppressWarnings("unchecked")
		Class<? extends BitcoindJsonRpcResponse<?>> responseType = (Class<? extends BitcoindJsonRpcResponse<?>>) Class.forName("dk.clanie.bitcoin.client.response." + className);

		// Deserialize and re-serialize
		log.debug("Deserializing " + jsonSample);
		BitcoindJsonRpcResponse<?> response = objectMapper.readValue(jsonSample, responseType);
		String roundtrippedJson = objectMapper.writeValueAsString(response);
		assertThat("json -> obj -> json roundtrip serialization failed for " + file.getName() + ".", roundtrippedJson, equalTo(jsonSample));

		// Check that all fields are explicitly mapped.
		assertThat("Some fields in response not explicitly mapped (see otherFields): " + response.toString(), response.getOtherFields().size(), equalTo(0));
		
		Object resultObject = response.getResult();
		if (resultObject instanceof JsonExtra) {