package utils.json;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import utils.Utils;

public abstract class JsonObject<T> implements Comparable<T>
{
	/**
	 * Debugging method.
	 * @return A string containing all the instance variable names and their corresponding values.
	 */
	protected String varDumpAll(){
		String result = this.getClass().getSimpleName()+"[";
		Field[] fields = this.getClass().getDeclaredFields();
		result += String.join(",", 
					java.util.Arrays.stream(fields)
						.filter(field->
								!Modifier.isStatic(field.getModifiers())
						).map(this::varDump).toArray(String[]::new)
				);
		result += "]";
		return result;
	}
	/**
	 * Debugging method.
	 * @return A string containing the variable's name and its corresponding values.
	 */
	protected String varDump(Field f){
		String result="\""+f.getName()+"\":\"";
		try
		{
			f.setAccessible(true);
			Object o = f.get(this);
			return result + Utils.escapeString(o.toString()) + "\"";
		}
		catch(IllegalArgumentException | IllegalAccessException
				| SecurityException e)
		{
			// Something horrible happened!
			System.err.println("Failed to get value of variable "+f.getName()+
					" of object at "+Integer.toHexString(System.identityHashCode(this)));
			e.printStackTrace();
			return result+"null\"";
		}
	}
}

@@ -855,21 +855,19 @@
 e()+%22%5C%22:
-%5C%22
 %22;%0A
+
 %09%09try%0A%09%09
@@ -939,16 +939,22 @@
 result +
+ %22%5C%22%22+
  Utils.e
@@ -991,16 +991,82 @@
 %22%22;%0A%09%09%7D%0A
+%09%09catch(NullPointerException npe)%7B%0A%09%09%09return result + %22null%22;%0A%09%09%7D%0A
 %09%09catch(

Fix NullPointerException