Commits

John Marsden committed fd834a9

Improve the JSON Document Marshaler. Check out the Nebulous Server Test, its pretty damn cool.

Comments (0)

Files changed (7)

src/main/java/cc/plural/jsonij/JSON.java

 import java.io.Reader;
 
 import cc.plural.jsonij.parser.ParserException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 
 /**
  * JSON document class.
     public static JSON parse(java.lang.String document) throws ParserException, IOException {
         return new JSON(parser.parse(document));
     }
+    
+    public static JSON parse(InputStream documentStream) throws ParserException, IOException {
+        return new JSON(parser.parse(new InputStreamReader(documentStream)));
+    }
 
     /**
      * Parse Method that parses from a Reader. The messageReader should be

src/main/java/cc/plural/jsonij/JSONMarshaler.java

 import cc.plural.jsonij.marshal.JSONMarshalerException;
 import cc.plural.jsonij.marshal.JavaMarshaler;
 import cc.plural.jsonij.parser.ParserException;
+import java.io.InputStream;
 
 /**
  *
         Object marshaledObject = jsonMarshaler.marshalJSONDocument(value, c);
         return marshaledObject;
     }
-
+    
+    public static Object marshalJSON(InputStream stream, Class<?> c) throws JSONMarshalerException {
+        Object marshaledObject = jsonMarshaler.marshalJSONDocument(stream, c);
+        return marshaledObject;
+    }
 }

src/main/java/cc/plural/jsonij/marshal/JSONDocumentMarshaler.java

 
 import cc.plural.jsonij.JSON;
 import cc.plural.jsonij.Value;
+import cc.plural.jsonij.parser.ParserException;
+import java.io.IOException;
+import java.io.InputStream;
 
 /**
  *
     public static String innerObjectAttribute;
 
     static {
-        innerArrayAttribute = "_innerArray";
-        innerObjectAttribute = "_innerObject";
+	innerArrayAttribute = "_innerArray";
+	innerObjectAttribute = "_innerObject";
     }
 
     public Object marshalJSONDocument(JSON json, Class<?> objectClass) throws JSONMarshalerException {
-        Object resultObject = null;
-        Value jsonRoot = json.getRoot();
-        if (jsonRoot.type() == Value.TYPE.OBJECT) {
-            JSON.Object<CharSequence, Value> jsonObjectRoot = (JSON.Object<CharSequence, Value>) jsonRoot;
-            resultObject = marshalJSONDocumentObject(jsonObjectRoot, objectClass);
-        } else if (jsonRoot.type() == Value.TYPE.ARRAY) {
-            JSON.Array<Value> jsonArrayRoot = (JSON.Array<Value>) jsonRoot;
-            resultObject = marshalJSONDocumentArray(jsonArrayRoot, objectClass);
-        } else {
-            //throw new Exception();
-        }
-        return resultObject;
+	Object resultObject = null;
+	Value jsonRoot = json.getRoot();
+	if (jsonRoot.type() == Value.TYPE.OBJECT) {
+	    JSON.Object<CharSequence, Value> jsonObjectRoot = (JSON.Object<CharSequence, Value>) jsonRoot;
+	    resultObject = marshalJSONDocumentObject(jsonObjectRoot, objectClass);
+	} else if (jsonRoot.type() == Value.TYPE.ARRAY) {
+	    JSON.Array<Value> jsonArrayRoot = (JSON.Array<Value>) jsonRoot;
+	    resultObject = marshalJSONDocumentArray(jsonArrayRoot, objectClass);
+	} else {
+	    //throw new Exception();
+	}
+	return resultObject;
     }
-    
-    
+
     public Object marshalJSONDocument(Value value, Class<?> objectClass) throws JSONMarshalerException {
-        Object resultObject = null;
-        if (value.type() == Value.TYPE.OBJECT) {
-            JSON.Object<CharSequence, Value> jsonObjectRoot = (JSON.Object<CharSequence, Value>) value;
-            resultObject = marshalJSONDocumentObject(jsonObjectRoot, objectClass);
-        } else if (value.type() == Value.TYPE.ARRAY) {
-            JSON.Array<Value> jsonArrayRoot = (JSON.Array<Value>) value;
-            resultObject = marshalJSONDocumentArray(jsonArrayRoot, objectClass);
-        } else {
-            //throw new Exception();
-        }
-        return resultObject;
+	Object resultObject = null;
+	if (value.type() == Value.TYPE.OBJECT) {
+	    JSON.Object<CharSequence, Value> jsonObjectRoot = (JSON.Object<CharSequence, Value>) value;
+	    resultObject = marshalJSONDocumentObject(jsonObjectRoot, objectClass);
+	} else if (value.type() == Value.TYPE.ARRAY) {
+	    JSON.Array<Value> jsonArrayRoot = (JSON.Array<Value>) value;
+	    resultObject = marshalJSONDocumentArray(jsonArrayRoot, objectClass);
+	} else {
+	    //throw new Exception();
+	}
+	return resultObject;
     }
 
     public Object marshalJSONDocumentObject(JSON.Object<CharSequence, Value> jsonObject, Class<?> objectClass) throws JSONMarshalerException {
-        Object resultObject = null;
-
-        Set<Entry<CharSequence, Value>> entrySet = jsonObject.entrySet();
-        Iterator<Entry<CharSequence, Value>> entrySetIterator = entrySet.iterator();
-        Entry<CharSequence, Value> entry = null;
-        Inspector inspector = new Inspector(objectClass);
-        inspector.inspect();
-
-        List<MarshalerPropertyValue> marshalPropertyValues = new ArrayList<MarshalerPropertyValue>();
-        while (entrySetIterator.hasNext()) {
-            entry = entrySetIterator.next();
-            if (entry.getKey().toString().equals(innerObjectAttribute) && inspector.hasInnerObject()) {
-                /**
-                 * todo: handle the inner object
-                 */
-            }
-            String propertyName = entry.getKey().toString();
-            if (inspector.hasProperty(propertyName)) {
-                MarshalerPropertyValue propertyValue = new MarshalerPropertyValue(propertyName, inspector.getProperty(propertyName), entry.getValue());
-                marshalPropertyValues.add(propertyValue);
-            }
-        }
-
-
-        try {
-            resultObject = objectClass.newInstance();
-            for (MarshalerPropertyValue propertyValue : marshalPropertyValues) {
-                if (propertyValue.getValue().isNull()) {
-                    // TODO: Handle Null
-                }
-                InspectorProperty property = propertyValue.getProperty();
-                if (property.getAccessPropertyType() == InspectorProperty.TYPE.METHOD) {
-                    Method method = objectClass.getMethod(property.getMutateName(), property.getMutateInputType());
-                    JavaType mutateType = JavaType.inspectObjectType(property.getMutateInputType());
-                    
-                    JSON.Array<Value> arrayJSON = null;
-                    
-                    switch (mutateType) {
-                        case BOOLEAN:
-                            method.invoke(resultObject, propertyValue.getValue().getBoolean());
-                            break;
-                        case BYTE:
-                            method.invoke(resultObject, propertyValue.getValue().getNumber().byteValue());
-                            break;
-                        case INTEGER:
-                            method.invoke(resultObject, propertyValue.getValue().getNumber().intValue());
-                            break;
-                        case SHORT:
-                            method.invoke(resultObject, propertyValue.getValue().getNumber().shortValue());
-                            break;
-                        case FLOAT:
-                            method.invoke(resultObject, propertyValue.getValue().getNumber().floatValue());
-                            break;
-                        case LONG:
-                            method.invoke(resultObject, propertyValue.getValue().getNumber().longValue());
-                            break;
-                        case DOUBLE:
-                            method.invoke(resultObject, propertyValue.getValue().getNumber().doubleValue());
-                            break;
-                        case STRING:
-                            method.invoke(resultObject, propertyValue.getValue().getString());
-                            break;
-                        case ENUM:
-                        	method.invoke(resultObject, propertyValue.getValue().getString());
-                            break;
-                        case MAP:
-
-                            break;
-                        case LIST:
-
-                            break;
-                        case OBJECT:
-                            JSON.Object<CharSequence, Value> objectJSON = (JSON.Object<CharSequence, Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentObject(objectJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY:                            
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_BYTE:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_SHORT:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_INTEGER:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_FLOAT:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_DOUBLE:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_LONG:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_STRING:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_ENUM:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_LIST:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_MAP:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        default:
-
-                            break;
-                    }
-                } else if (property.getAccessPropertyType() == InspectorProperty.TYPE.FIELD) {
-                    Field field = objectClass.getField(propertyValue.getProperty().getMutateName());
-                    JavaType mutateType = JavaType.inspectObjectType(property.getMutateInputType());
-                    
-                    JSON.Array<Value> arrayJSON = null;
-                    
-                    switch (mutateType) {
-                        case BOOLEAN:
-                            field.set(resultObject, propertyValue.getValue().getBoolean());
-                            break;
-                        case BYTE:
-                            field.set(resultObject, propertyValue.getValue().getNumber().byteValue());
-                            break;
-                        case INTEGER:
-                            field.set(resultObject, propertyValue.getValue().getNumber().intValue());
-                            break;
-                        case SHORT:
-                            field.set(resultObject, propertyValue.getValue().getNumber().shortValue());
-                            break;
-                        case FLOAT:
-                            field.set(resultObject, propertyValue.getValue().getNumber().floatValue());
-                            break;
-                        case LONG:
-                            field.set(resultObject, propertyValue.getValue().getNumber().longValue());
-                            break;
-                        case DOUBLE:
-                            field.set(resultObject, propertyValue.getValue().getNumber().doubleValue());
-                            break;
-                        case STRING:
-                            field.set(resultObject, propertyValue.getValue().getString());
-                            break;
-                        case ENUM:
-
-                            break;
-                        case MAP:
-
-                            break;
-                        case LIST:
-
-                            break;
-                        case OBJECT:
-                            JSON.Object<CharSequence, Value> objectJSON = (JSON.Object<CharSequence, Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentObject(objectJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_BYTE:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_SHORT:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_INTEGER:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_FLOAT:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_DOUBLE:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_LONG:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_STRING:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_ENUM:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_LIST:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_MAP:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        case ARRAY_ARRAY:
-                            arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
-                            field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
-                            break;
-                        default:
-
-                            break;
-                    }
-                }
-
-            }
-
-        }
-        catch (InstantiationException ex) {
-            Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        catch (IllegalAccessException ex) {
-            Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        catch (NoSuchFieldException ex) {
-            Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        catch (NoSuchMethodException ex) {
-            Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        catch (InvocationTargetException ex) {
-            Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        return resultObject;
+	Object resultObject = null;
+
+	Set<Entry<CharSequence, Value>> entrySet = jsonObject.entrySet();
+	Iterator<Entry<CharSequence, Value>> entrySetIterator = entrySet.iterator();
+	Entry<CharSequence, Value> entry = null;
+	Inspector inspector = new Inspector(objectClass);
+	inspector.inspect();
+
+	List<MarshalerPropertyValue> marshalPropertyValues = new ArrayList<MarshalerPropertyValue>();
+	while (entrySetIterator.hasNext()) {
+	    entry = entrySetIterator.next();
+	    if (entry.getKey().toString().equals(innerObjectAttribute) && inspector.hasInnerObject()) {
+		/**
+		 * todo: handle the inner object
+		 */
+	    }
+	    String propertyName = entry.getKey().toString();
+	    if (inspector.hasProperty(propertyName)) {
+		MarshalerPropertyValue propertyValue = new MarshalerPropertyValue(propertyName, inspector.getProperty(propertyName), entry.getValue());
+		marshalPropertyValues.add(propertyValue);
+	    }
+	}
+
+
+	try {
+	    resultObject = objectClass.newInstance();
+	    for (MarshalerPropertyValue propertyValue : marshalPropertyValues) {
+		if (propertyValue.getValue().isNull()) {
+		    // TODO: Handle Null
+		}
+		InspectorProperty property = propertyValue.getProperty();
+		if (property.getAccessPropertyType() == InspectorProperty.TYPE.METHOD) {
+		    Method method = objectClass.getMethod(property.getMutateName(), property.getMutateInputType());
+		    JavaType mutateType = JavaType.inspectObjectType(property.getMutateInputType());
+
+		    JSON.Array<Value> arrayJSON = null;
+
+		    switch (mutateType) {
+			case BOOLEAN:
+			    method.invoke(resultObject, propertyValue.getValue().getBoolean());
+			    break;
+			case BYTE:
+			    method.invoke(resultObject, propertyValue.getValue().getNumber().byteValue());
+			    break;
+			case INTEGER:
+			    method.invoke(resultObject, propertyValue.getValue().getNumber().intValue());
+			    break;
+			case SHORT:
+			    method.invoke(resultObject, propertyValue.getValue().getNumber().shortValue());
+			    break;
+			case FLOAT:
+			    method.invoke(resultObject, propertyValue.getValue().getNumber().floatValue());
+			    break;
+			case LONG:
+			    method.invoke(resultObject, propertyValue.getValue().getNumber().longValue());
+			    break;
+			case DOUBLE:
+			    method.invoke(resultObject, propertyValue.getValue().getNumber().doubleValue());
+			    break;
+			case STRING:
+			    method.invoke(resultObject, propertyValue.getValue().getString());
+			    break;
+			case ENUM:
+			    method.invoke(resultObject, propertyValue.getValue().getString());
+			    break;
+			case MAP:
+
+			    break;
+			case LIST:
+
+			    break;
+			case OBJECT:
+			    JSON.Object<CharSequence, Value> objectJSON = (JSON.Object<CharSequence, Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentObject(objectJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_BYTE:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_SHORT:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_INTEGER:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_FLOAT:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_DOUBLE:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_LONG:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_STRING:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_ENUM:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_LIST:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_MAP:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    method.invoke(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			default:
+
+			    break;
+		    }
+		} else if (property.getAccessPropertyType() == InspectorProperty.TYPE.FIELD) {
+		    Field field = objectClass.getField(propertyValue.getProperty().getMutateName());
+		    JavaType mutateType = JavaType.inspectObjectType(property.getMutateInputType());
+
+		    JSON.Array<Value> arrayJSON = null;
+
+		    switch (mutateType) {
+			case BOOLEAN:
+			    field.set(resultObject, propertyValue.getValue().getBoolean());
+			    break;
+			case BYTE:
+			    field.set(resultObject, propertyValue.getValue().getNumber().byteValue());
+			    break;
+			case INTEGER:
+			    field.set(resultObject, propertyValue.getValue().getNumber().intValue());
+			    break;
+			case SHORT:
+			    field.set(resultObject, propertyValue.getValue().getNumber().shortValue());
+			    break;
+			case FLOAT:
+			    field.set(resultObject, propertyValue.getValue().getNumber().floatValue());
+			    break;
+			case LONG:
+			    field.set(resultObject, propertyValue.getValue().getNumber().longValue());
+			    break;
+			case DOUBLE:
+			    field.set(resultObject, propertyValue.getValue().getNumber().doubleValue());
+			    break;
+			case STRING:
+			    field.set(resultObject, propertyValue.getValue().getString());
+			    break;
+			case ENUM:
+
+			    break;
+			case MAP:
+
+			    break;
+			case LIST:
+
+			    break;
+			case OBJECT:
+			    JSON.Object<CharSequence, Value> objectJSON = (JSON.Object<CharSequence, Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentObject(objectJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_BYTE:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_SHORT:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_INTEGER:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_FLOAT:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_DOUBLE:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_LONG:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_STRING:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_ENUM:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_LIST:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_MAP:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			case ARRAY_ARRAY:
+			    arrayJSON = (JSON.Array<Value>) propertyValue.getValue();
+			    field.set(resultObject, marshalJSONDocumentArray(arrayJSON, property.getMutateInputType()));
+			    break;
+			default:
+
+			    break;
+		    }
+		}
+
+	    }
+
+	} catch (InstantiationException ex) {
+	    Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
+	} catch (IllegalAccessException ex) {
+	    Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
+	} catch (NoSuchFieldException ex) {
+	    Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
+	} catch (NoSuchMethodException ex) {
+	    Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
+	} catch (InvocationTargetException ex) {
+	    Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, null, ex);
+	}
+	return resultObject;
     }
-    /*
-    public Object marshalJSONDocumentArray(JSON.Array<Value> jsonArray, Class<?> objectClass) {
-
 
-        return null;
-    }
-    */
-    
-    public Object marshalJSONDocumentArray(JSON.Array<Value> jsonArray, Class<?> objectClass) {
-        int size = jsonArray.size();
-        Object array = Array.newInstance(objectClass.getComponentType(), size);
-        for (int i = 0; i < size; i++) {
-            Array.set(array, i, jsonArray.get(i).getNumber().intValue());
-        }
-        return array;
-    }
-    
-    /*
-    public boolean[] marshalJSONDocumentIntegerArrayPrimitive(JSON.Array<Value> jsonArray, Class<?> objectClass) {
-        int size = jsonArray.size();
-        boolean[] array = (boolean[]) Array.newInstance(objectClass.getComponentType(), size);
-        for (int i = 0; i < size; i++) {
-            Array.set(array, i, jsonArray.get(i).getNumber().intValue());
-        }
-        return array;
+    public Object marshalJSONDocument(InputStream stream, Class<?> objectClass) throws JSONMarshalerException {
+	JSON json;
+	try {
+	    json = JSON.parse(stream);
+
+	} catch (ParserException ex) {
+	    throw new JSONMarshalerException("", ex);
+	} catch (IOException ex) {
+	    throw new JSONMarshalerException("", ex);
+	}
+	return marshalJSONDocument(json, objectClass);
     }
 
-    public Boolean[] marshalJSONDocumentIntegerArray(JSON.Array<Value> jsonArray, Class<?> objectClass) {
-        int size = jsonArray.size();
-        Boolean[] array = (Boolean[]) Array.newInstance(objectClass.getComponentType(), size);
-        for (int i = 0; i < size; i++) {
-            Array.set(array, i, jsonArray.get(i).getNumber().intValue());
-        }
-        return array;
-    }
-    
-    
-    public int[] marshalJSONDocumentIntegerArrayPrimitive(JSON.Array<Value> jsonArray, Class<?> objectClass) {
-        int size = jsonArray.size();
-        int[] array = (int[]) Array.newInstance(objectClass.getComponentType(), size);
-        for (int i = 0; i < size; i++) {
-            Array.set(array, i, jsonArray.get(i).getNumber().intValue());
-        }
-        return array;
+    public Object marshalJSONDocument(String jsonString, Class<?> objectClass) throws JSONMarshalerException {
+	JSON json;
+	try {
+	    json = JSON.parse(jsonString);
+
+	} catch (ParserException ex) {
+	    throw new JSONMarshalerException("", ex);
+	} catch (IOException ex) {
+	    throw new JSONMarshalerException("", ex);
+	}
+	return marshalJSONDocument(json, objectClass);
     }
 
-    public Integer[] marshalJSONDocumentIntegerArray(JSON.Array<Value> jsonArray, Class<?> objectClass) {
-        int size = jsonArray.size();
-        Integer[] array = (Integer[]) Array.newInstance(objectClass.getComponentType(), size);
-        for (int i = 0; i < size; i++) {
-            Array.set(array, i, jsonArray.get(i).getNumber().intValue());
-        }
-        return array;
+    /*
+     * public Object marshalJSONDocumentArray(JSON.Array<Value> jsonArray,
+     * Class<?> objectClass) {
+     *
+     *
+     * return null; }
+     */
+    public Object marshalJSONDocumentArray(JSON.Array<Value> jsonArray, Class<?> objectClass) throws JSONMarshalerException {
+	int size = jsonArray.size();
+	Class<?> componentClass = objectClass.getComponentType();
+	Object array = Array.newInstance(componentClass, size);
+	for (int i = 0; i < size; i++) {
+	    Value value =  jsonArray.get(i);
+	    if(value.getValueType() == Value.TYPE.OBJECT) {
+		Array.set(array, i, marshalJSONDocumentObject((JSON.Object<CharSequence, Value>) value, componentClass));
+	    } else if(value.getValueType() == Value.TYPE.ARRAY) {
+		Array.set(array, i, marshalJSONDocumentArray((JSON.Array<Value>) value, componentClass));
+	    } else if (componentClass.equals(int.class)) {
+		Array.set(array, i, jsonArray.get(i).getNumber().intValue());
+	    } else if (componentClass.equals(float.class)) {
+		Array.set(array, i, jsonArray.get(i).getNumber().floatValue());
+	    } else if (componentClass.equals(double.class)) {
+		Array.set(array, i, jsonArray.get(i).getNumber().doubleValue());
+	    } else if (componentClass.equals(byte.class)) {
+		Array.set(array, i, jsonArray.get(i).getNumber().byteValue());
+	    } else if (componentClass.equals(boolean.class)) {
+		Array.set(array, i, jsonArray.get(i).getBoolean());
+	    } else if (componentClass.equals(String.class)) {
+		Array.set(array, i, jsonArray.get(i).getString());
+	    } else {
+		//
+	    }
+	}
+	return array;
     }
-    */
 
+    /*
+     * public boolean[]
+     * marshalJSONDocumentIntegerArrayPrimitive(JSON.Array<Value> jsonArray,
+     * Class<?> objectClass) { int size = jsonArray.size(); boolean[] array =
+     * (boolean[]) Array.newInstance(objectClass.getComponentType(), size); for
+     * (int i = 0; i < size; i++) { Array.set(array, i,
+     * jsonArray.get(i).getNumber().intValue()); } return array; }
+     *
+     * public Boolean[] marshalJSONDocumentIntegerArray(JSON.Array<Value>
+     * jsonArray, Class<?> objectClass) { int size = jsonArray.size(); Boolean[]
+     * array = (Boolean[]) Array.newInstance(objectClass.getComponentType(),
+     * size); for (int i = 0; i < size; i++) { Array.set(array, i,
+     * jsonArray.get(i).getNumber().intValue()); } return array; }
+     *
+     *
+     * public int[] marshalJSONDocumentIntegerArrayPrimitive(JSON.Array<Value>
+     * jsonArray, Class<?> objectClass) { int size = jsonArray.size(); int[]
+     * array = (int[]) Array.newInstance(objectClass.getComponentType(), size);
+     * for (int i = 0; i < size; i++) { Array.set(array, i,
+     * jsonArray.get(i).getNumber().intValue()); } return array; }
+     *
+     * public Integer[] marshalJSONDocumentIntegerArray(JSON.Array<Value>
+     * jsonArray, Class<?> objectClass) { int size = jsonArray.size(); Integer[]
+     * array = (Integer[]) Array.newInstance(objectClass.getComponentType(),
+     * size); for (int i = 0; i < size; i++) { Array.set(array, i,
+     * jsonArray.get(i).getNumber().intValue()); } return array; }
+     */
     public static class MarshalerPropertyValue {
 
-        String name;
-        InspectorProperty property;
-        Value value;
-
-        public MarshalerPropertyValue() {
-            this.name = null;
-            this.property = null;
-            this.value = null;
-        }
-
-        public MarshalerPropertyValue(String name, InspectorProperty property, Value value) {
-            this.name = name;
-            this.property = property;
-            this.value = value;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        public InspectorProperty getProperty() {
-            return property;
-        }
-
-        public void setProperty(InspectorProperty property) {
-            this.property = property;
-        }
-
-        public Value getValue() {
-            return value;
-        }
-
-        public void setValue(Value value) {
-            this.value = value;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder resultBuilder = new StringBuilder();
-            resultBuilder.append("MarshalerPropertyValue [Name:").append(name).append('|');
-            resultBuilder.append("Property:").append(property);
-            resultBuilder.append("->");
-            resultBuilder.append("Value:").append(value).append(']');
-            return resultBuilder.toString();
-        }
+	String name;
+	InspectorProperty property;
+	Value value;
+
+	public MarshalerPropertyValue() {
+	    this.name = null;
+	    this.property = null;
+	    this.value = null;
+	}
+
+	public MarshalerPropertyValue(String name, InspectorProperty property, Value value) {
+	    this.name = name;
+	    this.property = property;
+	    this.value = value;
+	}
+
+	public String getName() {
+	    return name;
+	}
+
+	public void setName(String name) {
+	    this.name = name;
+	}
+
+	public InspectorProperty getProperty() {
+	    return property;
+	}
+
+	public void setProperty(InspectorProperty property) {
+	    this.property = property;
+	}
+
+	public Value getValue() {
+	    return value;
+	}
+
+	public void setValue(Value value) {
+	    this.value = value;
+	}
+
+	@Override
+	public String toString() {
+	    StringBuilder resultBuilder = new StringBuilder();
+	    resultBuilder.append("MarshalerPropertyValue [Name:").append(name).append('|');
+	    resultBuilder.append("Property:").append(property);
+	    resultBuilder.append("->");
+	    resultBuilder.append("Value:").append(value).append(']');
+	    return resultBuilder.toString();
+	}
     }
 }

src/test/java/cc/plural/jsonij/marshal/NebulousServerTest.java

+/*
+ * Copyright 2012 jmarsden.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package cc.plural.jsonij.marshal;
+
+import cc.plural.jsonij.JSON;
+import cc.plural.jsonij.JSONMarshaler;
+import cc.plural.jsonij.parser.ParserException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import org.junit.Test;
+
+/**
+ *
+ * @author jmarsden
+ */
+public class NebulousServerTest {
+
+    @Test
+    public void testMarshalConfiguration() throws JSONMarshalerException, IOException, ParserException {
+	URL url = getClass().getResource("/etc/config.json");
+	InputStream stream = url.openStream();
+
+	Object object = JSONMarshaler.marshalJSON(stream, NebulousConfig.class);
+
+	JSON output = JSONMarshaler.marshalObject(object);
+	System.out.println(output.toJSON());
+    }
+
+    public static class NebulousConfig {
+
+	HttpConfig http;
+
+	public NebulousConfig() {
+	    http = null;
+	}
+
+	public HttpConfig getHttp() {
+	    return http;
+	}
+
+	public void setHttp(HttpConfig http) {
+	    this.http = http;
+	}
+    }
+
+    public static class HttpConfig {
+
+	String handler;
+	String[] index;
+	String mime;
+	String defaultMime;
+	ServerConfig server[];
+
+	public HttpConfig() {
+	    handler = null;
+	}
+
+	public String getHandler() {
+	    return handler;
+	}
+
+	public void setHandler(String handler) {
+	    this.handler = handler;
+	}
+
+	public String[] getIndex() {
+	    return index;
+	}
+
+	public void setIndex(String[] index) {
+	    this.index = index;
+	}
+
+	public String getDefaultMime() {
+	    return defaultMime;
+	}
+
+	public void setDefaultMime(String defaultMime) {
+	    this.defaultMime = defaultMime;
+	}
+
+	public String getMime() {
+	    return mime;
+	}
+
+	public void setMime(String mime) {
+	    this.mime = mime;
+	}
+
+	public ServerConfig[] getServer() {
+	    return server;
+	}
+
+	public void setServer(ServerConfig[] server) {
+	    this.server = server;
+	}
+    }
+
+    public static class ServerConfig {
+
+	public int[] port;
+	public LocationConfig[] location;
+	
+	public ServerConfig() {
+	    port = null;
+	    location = null;
+	}
+    }
+
+    public static class LocationConfig {
+
+	public String host;
+	public String path;
+	public RendererConfig renderer;
+	public String accessLog;
+	public String errorLog;
+    }
+
+    public static class RendererConfig {
+
+	public String handler;
+	public String jar;
+    }
+}

src/test/resources/etc/config.json

+{
+    "http": {
+	"handler":"cc.plural.http.HttpHandler",
+	"index":["index.html","index.htm"],
+	"mime":"mime.json",
+	"defaultMime":"application/octet-stream",
+	"server": [
+	{
+	    "port":[10909],
+	    "location": [
+	    {
+		"host":"*",
+		"path":"^/(img|css|js|error)/", 
+		"renderer":{
+		    "handler":"cc.plural.http.renderer.JarRenderer", 
+		    "jar":"/lib/nebulusWWW.jar"
+		}, 
+		"accessLog":"localhost.static.access.log", 
+		"errorLog": "localhost.static.error.log"
+	    },
+	    {
+		"host":"*",
+		"path":"/ws",
+		"renderer":{
+		    "handler":"cc.plural.websocket.WebSocketRenderer"
+		},
+		"accessLog":"localhost.ws.access.log", 
+		"errorLog": "localhost.ws.error.log"
+	    },
+	    {	
+		"host":"*",
+		"path":"/", 
+		"renderer":{
+		    "handler":"cc.plural.http.renderer.TemplateRenderer"
+		}, 
+		"accessLog":"localhost.access.log", 
+		"errorLog": "localhost.error.log"
+	    }
+	    ]
+	}
+	]
+    }
+}

src/test/resources/etc/http/header.json

+{
+	"Cache-Control":		{"type":"General"},
+	"Connection":			{"type":"General"},
+	"Date":				{"type":"General",	"class":"cc.plural.http.headers.DateValue"},
+	"Pragma":			{"type":"General"},
+	"Trailer":			{"type":"General"},
+	"Transfer-Encoding":            {"type":"General"},
+	"Upgrade":			{"type":"General"},
+	"Via":                          {"type":"General"},
+	"Warning": 			{"type":"General"},
+	
+	"Accept": 			{"type":"Request"},
+	"Accept-Charset": 		{"type":"Request"},
+	"Accept-Encoding": 		{"type":"Request"},
+	"Accept-Language": 		{"type":"Request"},
+	"Authorization": 		{"type":"Request"},
+	"Expect": 			{"type":"Request"},
+	"From": 			{"type":"Request"},
+	"Host": 			{"type":"Request",	"class":"cc.plural.http.headers.HostHeader"},
+	"If-Match": 			{"type":"Request"},
+	"If-Modified-Since":            {"type":"Request"},
+	"If-None-Match": 		{"type":"Request"},
+	"If-Range": 			{"type":"Request"},
+	"If-Unmodified-Since":          {"type":"Request"},
+	"Max-Forwards": 		{"type":"Request"},
+	"Proxy-Authorization":          {"type":"Request"},
+	"Range": 			{"type":"Request"},
+	"Referer": 			{"type":"Request"},
+	"TE": 				{"type":"Request"},
+	"User-Agent": 			{"type":"Request"},
+	
+	"Accept-Ranges": 		{"type":"Response"},
+	"Age": 				{"type":"Response"},
+	"Etag":	 			{"type":"Response"},
+	"Location": 			{"type":"Response"},
+	"Proxy-Authenticate":           {"type":"Response"},
+	"Retry-After": 			{"type":"Response"},
+	"Server":			{"type":"Response"},
+	"Vary":				{"type":"Response"},
+	"WWW-Authenticate":		{"type":"Response"},
+	
+	"Allow":			{"type":"Entity"},
+	"Content-Encoding":		{"type":"Entity"},
+	"Content-Language":		{"type":"Entity"},
+	"Content-Length":		{"type":"Entity"},
+	"Content-Location":		{"type":"Entity"},
+	"Content-MD5":			{"type":"Entity"},
+	"Content-Range":		{"type":"Entity"},
+	"Content-Type":			{"type":"Entity"},
+	"Expires":			{"type":"Entity"},
+	"Last-Modified":		{"type":"Entity",	"class":"cc.plural.http.headers.DateValue"},
+	"extension-header":		{"type":"Entity"}
+}

src/test/resources/etc/mime.json

+{
+
+	"asc":"text/plain",
+	"brf":"text/plain",
+	
+	
+	"css":"text/css",
+	"csv":"text/csv",
+	
+	"gif":"image/gif",
+	"ief":"image/ief",
+	
+	
+	"html":"text/html",
+	"htm":"text/html",
+	
+	"jpe":"image/jpeg",
+	"jpeg":"image/jpeg",
+	"jpg":"image/jpeg",
+	
+	
+	"png":"image/png",
+	"pot":"text/plain",
+	
+	"shtml":"text/html",
+	"txt":"text/plain",
+	"text":"text/plain"
+
+}