Commits

John Marsden  committed 917840b

Update to 0.0.3

  • Participants
  • Parent commits c8f3a0d

Comments (0)

Files changed (7)

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

 
     public Object marshalJSONDocument(Value value, Class<?> objectClass) throws JSONMarshalerException {
         Object resultObject = null;
-        if (JavaMarshalerObjects.hasCodec(objectClass)) {
+        if (JSONMarshaler.hasCodec(objectClass)) {
 //            JSONCodec codec = JavaMarshalerObjects.getCodec(objectClass);
 //            resultObject = codec.decode(value);
         } else {
         return null;
     }
 
+    
     public Map<?, ?> marshalJSONDocumentMap(JSON.Object<CharSequence, Value> jsonMap, Class<?> objectClass) {
         System.out.println(objectClass);
         System.out.println(jsonMap);

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

 
 import cc.plural.jsonij.JSON;
 import cc.plural.jsonij.Value;
+import cc.plural.jsonij.marshal.codec.JSONValueCodec;
+import cc.plural.jsonij.marshal.codec.JSONValueCodecStore;
 import cc.plural.jsonij.parser.ParserException;
 import java.io.IOException;
 import java.io.InputStream;
     public static boolean ALWAYS_USE_INNER_PROPERTY;
     public static String INNER_ARRAY_PROPERTY;
     public static String INNER_OBJECT_PROPERTY;
+    static JSONValueCodecStore CODEC_STORE;
+    static int cycleLevels;
+
+    static {
+        cycleLevels = 0;
+    }
 
     static {
         JAVA_MARSHALLER = new JavaMarshaler();
         Object marshaledObject = JSON_DOCUMENT_MARSHALER.marshalJSONDocument(stream, c);
         return marshaledObject;
     }
+
+    public static void resetCodecStore() {
+        if (CODEC_STORE != null) {
+            CODEC_STORE = null;
+        }
+    }
+
+    public static boolean hasCodec(Class<?> codecType) {
+        if (CODEC_STORE == null) {
+            return false;
+        } else {
+            return CODEC_STORE.hasCodec(codecType);
+        }
+    }
+
+    public static void registerCodec(Class<?> type, Class<? extends JSONValueCodec> codec) {
+        if (CODEC_STORE == null) {
+            CODEC_STORE = new JSONValueCodecStore();
+        }
+        CODEC_STORE.registerCodec(type, codec);
+    }
+
+    public static JSONValueCodecStore.JSONValueCodecHelper getCodecHelper(Class<?> type) {
+        if (CODEC_STORE == null) {
+            return null;
+        } else {
+            return CODEC_STORE.getCodecHelper(type);
+        }
+    }
+
+    public static Class<? extends JSONValueCodec> getCodec(Class<?> type) {
+        if (CODEC_STORE == null) {
+            return null;
+        } else {
+            return CODEC_STORE.getCodec(type);
+        }
+    }
+
+    public static int getCycleLevels() {
+        return cycleLevels;
+    }
+
+    public static void setCycleLevels(int levels) {
+        cycleLevels = levels;
+    }
 }

File src/main/java/cc/plural/jsonij/marshal/JavaMarshalerObjects.java

 public class JavaMarshalerObjects {
 
     protected JavaMarshaler marshaler;
-    static JSONValueCodecStore codecStore;
-    static int cycleLevels;
-
-    static {
-        cycleLevels = 0;
-    }
 
     public JavaMarshalerObjects(JavaMarshaler marshaler) {
         this.marshaler = marshaler;
         }
 
         // Check for JSONCodec
-        if (codecStore != null && codecStore.hasCodec(objectClass)) {
-            JSONValueCodecHelper codecHelper = codecStore.getCodecHelper(objectClass);
+        if (JSONMarshaler.CODEC_STORE != null && JSONMarshaler.CODEC_STORE.hasCodec(objectClass)) {
+            JSONValueCodecHelper codecHelper = JSONMarshaler.CODEC_STORE.getCodecHelper(objectClass);
             Value value = codecHelper.encode(o);
             return value;
         }
                     || marshaledObject.getClass() == Long.class
                     || marshaledObject.getClass() == String.class) {
                 value = marshaler.marshalAnyObject(marshaledObject, cycleDetector.cloneCycleDetector());
-            } else if (!cycleDetector.hashDetected(hashCode) || cycleDetector.getHashCount(hashCode) < JavaMarshalerObjects.getCycleLevels()) {
+            } else if (!cycleDetector.hashDetected(hashCode) || cycleDetector.getHashCount(hashCode) < JSONMarshaler.getCycleLevels()) {
                 cycleDetector.addHash(hashCode);
                 value = marshaler.marshalAnyObject(marshaledObject, cycleDetector.cloneCycleDetector());
             } else {
                     || marshaledObject.getClass() == Long.class
                     || marshaledObject.getClass() == String.class) {
                 value = marshaler.marshalAnyObject(marshaledObject, cycleDetector.cloneCycleDetector());
-            } else if (!cycleDetector.hashDetected(hashCode) || cycleDetector.getHashCount(hashCode) < JavaMarshalerObjects.getCycleLevels()) {
+            } else if (!cycleDetector.hashDetected(hashCode) || cycleDetector.getHashCount(hashCode) < JSONMarshaler.getCycleLevels()) {
                 cycleDetector.addHash(hashCode);
                 value = marshaler.marshalAnyObject(marshaledObject, cycleDetector.cloneCycleDetector());
             } else {
         return value;
     }
 
-    public static void resetCodecStore() {
-        if (codecStore != null) {
-            codecStore = null;
-        }
-    }
-
-    public static boolean hasCodec(Class<?> codecType) {
-        if (codecStore == null) {
-            return false;
-        } else {
-            return codecStore.hasCodec(codecType);
-        }
-    }
-
-    public static void registerCodec(Class<?> type, Class<? extends JSONValueCodec> codec) {
-        if (codecStore == null) {
-            codecStore = new JSONValueCodecStore();
-        }
-        codecStore.registerCodec(type, codec);
-    }
-
-    public static JSONValueCodecHelper getCodecHelper(Class<?> type) {
-        if (codecStore == null) {
-            return null;
-        } else {
-            return codecStore.getCodecHelper(type);
-        }
-    }
-
-    public static Class<? extends JSONValueCodec> getCodec(Class<?> type) {
-        if (codecStore == null) {
-            return null;
-        } else {
-            return codecStore.getCodec(type);
-        }
-    }
-
-    public static int getCycleLevels() {
-        return cycleLevels;
-    }
-
-    public static void setCycleLevels(int levels) {
-        cycleLevels = levels;
-    }
+    
 }

File src/main/java/cc/plural/jsonij/reflect/ClassProperty.java

-/**
- * Copyright (C) 2012 J.W.Marsden <jmarsden@plural.cc>
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package cc.plural.jsonij.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.Objects;
-import sun.java2d.loops.DrawGlyphListAA;
-
-/**
- *
- * @author jmarsden@plural.cc
- */
-public class ClassProperty {
-
-    private Class<?> klass;
-    private String propertyName;
-    private ClassPropertyAccessor accessor;
-    private ClassPropertyMutator mutator;
-
-    public ClassProperty() {
-    }
-
-    public ClassPropertyAccessor getAccessor() {
-        return accessor;
-    }
-
-    public void setAccessor(ClassPropertyAccessor accessor) {
-        this.accessor = accessor;
-    }
-
-    public Class<?> getKlass() {
-        return klass;
-    }
-
-    public void setKlass(Class<?> klass) {
-        this.klass = klass;
-    }
-
-    public ClassPropertyMutator getMutator() {
-        return mutator;
-    }
-
-    public void setMutator(ClassPropertyMutator mutator) {
-        this.mutator = mutator;
-    }
-
-    public String getPropertyName() {
-        return propertyName;
-    }
-
-    public void setPropertyName(String propertyName) {
-        this.propertyName = propertyName;
-    }
-
-    public void registerAccessor(Field field) {
-        if (accessor == null) {
-            accessor = new ClassPropertyAccessor();
-            accessor.field = field;
-            accessor.klass = field.getDeclaringClass();
-            accessor.type = field.getType();
-            accessor.genericType = field.getGenericType();
-        } else if (accessor.field == null) {
-            accessor.field = field;
-        }
-    }
-
-    public void registorMutator(Field field) {
-        if (mutator == null) {
-            mutator = new ClassPropertyMutator();
-            mutator.field = field;
-            mutator.klass = field.getDeclaringClass();
-            mutator.type = field.getType();
-            mutator.genericType = field.getGenericType();
-        } else if (mutator.field == null) {
-            mutator.field = field;
-        }
-    }
-
-    public void registerAccessor(Method method) {
-        if (accessor == null) {
-            accessor = new ClassPropertyAccessor();
-            accessor.method = method;
-            accessor.klass = method.getDeclaringClass();
-            accessor.type = method.getReturnType();
-            accessor.genericType = method.getGenericReturnType();
-        } else if (accessor.method == null) {
-            accessor.method = method;
-        }
-    }
-
-    public void registorMutator(Method method) {
-        if (mutator == null) {
-            Class<?>[] argumentTypes = method.getParameterTypes();
-            Type[] argumentGenericTypes = method.getGenericParameterTypes();
-            if (argumentTypes.length == 1) {
-                mutator = new ClassPropertyMutator();
-                mutator.method = method;
-                mutator.klass = method.getDeclaringClass();
-                mutator.type = argumentTypes[0];
-                mutator.genericType = argumentGenericTypes[0];
-            }
-        } else if (mutator.method == null) {
-            mutator.method = method;
-        }
-    }
-
-    public boolean isValid() {
-        if (mutator != null && accessor != null && mutator.canAccess() && accessor.canAccess()) {
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final ClassProperty other = (ClassProperty) obj;
-        if (!Objects.equals(this.propertyName, other.propertyName)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        int hash = 3;
-        hash = 67 * hash + Objects.hashCode(this.klass);
-        hash = 67 * hash + Objects.hashCode(this.propertyName);
-        return hash;
-    }
-
-    @Override
-    public String toString() {
-        return klass.getSimpleName() + "." + propertyName + "(" + mutator + "): " + accessor;
-    }
-
-    public static class ClassPropertyAccessor {
-
-        private Class<?> klass;
-        private Class<?> type;
-        private Type genericType;
-        private Method method;
-        private Field field;
-
-        public Field getField() {
-            return field;
-        }
-
-        public void setField(Field field) {
-            this.field = field;
-        }
-
-        public Class<?> getKlass() {
-            return klass;
-        }
-
-        public void setKlass(Class<?> klass) {
-            this.klass = klass;
-        }
-
-        public Method getMethod() {
-            return method;
-        }
-
-        public void setMethod(Method method) {
-            this.method = method;
-        }
-
-        public Class<?> getType() {
-            return type;
-        }
-
-        public void setType(Class<?> type) {
-            this.type = type;
-        }
-
-        public Type getGenericType() {
-            return genericType;
-        }
-
-        public void setGenericType(Type genericType) {
-            this.genericType = genericType;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder builder = new StringBuilder();
-
-            if (field != null) {
-                int modifiers = field.getModifiers();
-                builder.append(getModifierString(modifiers));
-                builder.append('f');
-            }
-
-            if (method != null) {
-                int modifiers = method.getModifiers();
-                builder.append(getModifierString(modifiers));
-                builder.append('m');
-            }
-            builder.append('[');
-            builder.append(getTypeString(type));
-            builder.append(']');
-            return builder.toString();
-        }
-
-        public boolean canAccess() {
-            if (field != null && Modifier.isPublic(field.getModifiers())) {
-                return true;
-            }
-            if (method != null && Modifier.isPublic(method.getModifiers())) {
-                return true;
-            }
-            return false;
-        }
-
-        public boolean fieldType() {
-            if (field != null && Modifier.isPublic(field.getModifiers())) {
-                return true;
-            }
-            return false;
-        }
-
-        public boolean methodType() {
-            if (method != null && Modifier.isPublic(method.getModifiers())) {
-                return true;
-            }
-            return false;
-        }
-    }
-
-    public static class ClassPropertyMutator {
-
-        private Class<?> klass;
-        private Class<?> type;
-        private Type genericType;
-        private Method method;
-        private Field field;
-
-        public Field getField() {
-            return field;
-        }
-
-        public void setField(Field field) {
-            this.field = field;
-        }
-
-        public Class<?> getKlass() {
-            return klass;
-        }
-
-        public void setKlass(Class<?> klass) {
-            this.klass = klass;
-        }
-
-        public Method getMethod() {
-            return method;
-        }
-
-        public void setMethod(Method method) {
-            this.method = method;
-        }
-
-        public Class<?> getType() {
-            return type;
-        }
-
-        public void setType(Class<?> type) {
-            this.type = type;
-        }
-
-        public Type getGenericType() {
-            return genericType;
-        }
-
-        public void setGenericType(Type genericType) {
-            this.genericType = genericType;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder builder = new StringBuilder();
-
-            if (field != null) {
-                int modifiers = field.getModifiers();
-                builder.append(getModifierString(modifiers));
-                builder.append('f');
-            }
-
-            if (method != null) {
-                int modifiers = method.getModifiers();
-                builder.append(getModifierString(modifiers));
-                builder.append('m');
-            }
-            builder.append('[');
-            builder.append(getTypeString(type));
-            builder.append(']');
-            return builder.toString();
-        }
-
-        public boolean canAccess() {
-            if (field != null && Modifier.isPublic(field.getModifiers())) {
-                return true;
-            }
-            if (method != null && Modifier.isPublic(method.getModifiers())) {
-                return true;
-            }
-            return false;
-        }
-
-        public boolean fieldType() {
-            if (field != null && Modifier.isPublic(field.getModifiers())) {
-                return true;
-            }
-            return false;
-        }
-
-        public boolean methodType() {
-            if (method != null && Modifier.isPublic(method.getModifiers())) {
-                return true;
-            }
-            return false;
-        }
-
-        public void fire(Object object, boolean bool) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, bool);
-            }
-            if (fieldType()) {
-                field.set(object, bool);
-            }
-        }
-
-        public void fire(Object object, byte byteValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, byteValue);
-            }
-            if (fieldType()) {
-                field.set(object, byteValue);
-            }
-        }
-
-        public void fire(Object object, short shortValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, shortValue);
-            }
-            if (fieldType()) {
-                field.set(object, shortValue);
-            }
-        }
-
-        public void fire(Object object, float floatValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, floatValue);
-            }
-            if (fieldType()) {
-                field.set(object, floatValue);
-            }
-        }
-
-        public void fire(Object object, int intValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, intValue);
-            }
-            if (fieldType()) {
-                field.set(object, intValue);
-            }
-        }
-
-        public void fire(Object object, long longValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, longValue);
-            }
-            if (fieldType()) {
-                field.set(object, longValue);
-            }
-        }
-
-        public void fire(Object object, String string) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, string);
-            }
-            if (fieldType()) {
-                field.set(object, string);
-            }
-        }
-
-        public void fire(Object object, Object propertyObject) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-            if (methodType()) {
-                method.invoke(object, propertyObject);
-            }
-            if (fieldType()) {
-                field.set(object, propertyObject);
-            }
-        }
-    }
-
-    public static String getModifierString(int modifiers) {
-        String modifier = null;
-        if (Modifier.isPublic(modifiers)) {
-            modifier = "+";
-        } else if (Modifier.isPrivate(modifiers)) {
-            modifier = "-";
-        } else if (Modifier.isProtected(modifiers)) {
-            modifier = "#";
-        } else {
-            modifier = "%";
-        }
-        return modifier;
-    }
-
-    public static String getTypeString(Type genericType) {
-        StringBuilder builder = new StringBuilder();
-        if (genericType instanceof Class) {
-            Class<?> genericTypeClass = (Class<?>) genericType;
-            builder.append(genericTypeClass.getSimpleName());
-        } else if (genericType instanceof ParameterizedType) {
-            ParameterizedType genericParameterizedType = (ParameterizedType) genericType;
-            builder.append(getTypeString(genericParameterizedType.getRawType()));
-            Type[] innerTypes = genericParameterizedType.getActualTypeArguments();
-            builder.append('<');
-            if (innerTypes.length > 0) {
-                for (int i = 0; i < innerTypes.length - 1; i++) {
-                    builder.append(getTypeString(innerTypes[i])).append(',');
-                }
-                builder.append(getTypeString(innerTypes[innerTypes.length - 1]));
-            }
-            builder.append('>');
-        }
-        return builder.toString();
-    }
-}
+/**
+ * Copyright (C) 2012 J.W.Marsden <jmarsden@plural.cc>
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package cc.plural.jsonij.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Objects;
+
+/**
+ *
+ * @author jmarsden@plural.cc
+ */
+public class ClassProperty {
+
+    private Class<?> klass;
+    private String propertyName;
+    private ClassPropertyAccessor accessor;
+    private ClassPropertyMutator mutator;
+
+    public ClassProperty() {
+    }
+
+    public ClassPropertyAccessor getAccessor() {
+        return accessor;
+    }
+
+    public void setAccessor(ClassPropertyAccessor accessor) {
+        this.accessor = accessor;
+    }
+
+    public Class<?> getKlass() {
+        return klass;
+    }
+
+    public void setKlass(Class<?> klass) {
+        this.klass = klass;
+    }
+
+    public ClassPropertyMutator getMutator() {
+        return mutator;
+    }
+
+    public void setMutator(ClassPropertyMutator mutator) {
+        this.mutator = mutator;
+    }
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    public void setPropertyName(String propertyName) {
+        this.propertyName = propertyName;
+    }
+
+    public void registerAccessor(Field field) {
+        if (accessor == null) {
+            accessor = new ClassPropertyAccessor();
+            accessor.field = field;
+            accessor.klass = field.getDeclaringClass();
+            accessor.type = field.getType();
+            accessor.genericType = field.getGenericType();
+        } else if (accessor.field == null) {
+            accessor.field = field;
+        }
+    }
+
+    public void registorMutator(Field field) {
+        if (mutator == null) {
+            mutator = new ClassPropertyMutator();
+            mutator.field = field;
+            mutator.klass = field.getDeclaringClass();
+            mutator.type = field.getType();
+            mutator.genericType = field.getGenericType();
+        } else if (mutator.field == null) {
+            mutator.field = field;
+        }
+    }
+
+    public void registerAccessor(Method method) {
+        if (accessor == null) {
+            accessor = new ClassPropertyAccessor();
+            accessor.method = method;
+            accessor.klass = method.getDeclaringClass();
+            accessor.type = method.getReturnType();
+            accessor.genericType = method.getGenericReturnType();
+        } else if (accessor.method == null) {
+            accessor.method = method;
+        }
+    }
+
+    public void registorMutator(Method method) {
+        if (mutator == null) {
+            Class<?>[] argumentTypes = method.getParameterTypes();
+            Type[] argumentGenericTypes = method.getGenericParameterTypes();
+            if (argumentTypes.length == 1) {
+                mutator = new ClassPropertyMutator();
+                mutator.method = method;
+                mutator.klass = method.getDeclaringClass();
+                mutator.type = argumentTypes[0];
+                mutator.genericType = argumentGenericTypes[0];
+            }
+        } else if (mutator.method == null) {
+            mutator.method = method;
+        }
+    }
+
+    public boolean isValid() {
+        if (mutator != null && accessor != null && mutator.canAccess() && accessor.canAccess()) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final ClassProperty other = (ClassProperty) obj;
+        if (!Objects.equals(this.propertyName, other.propertyName)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 3;
+        hash = 67 * hash + Objects.hashCode(this.klass);
+        hash = 67 * hash + Objects.hashCode(this.propertyName);
+        return hash;
+    }
+
+    @Override
+    public String toString() {
+        return klass.getSimpleName() + "." + propertyName + "(" + mutator + "): " + accessor;
+    }
+
+    public static class ClassPropertyAccessor {
+
+        private Class<?> klass;
+        private Class<?> type;
+        private Type genericType;
+        private Method method;
+        private Field field;
+
+        public Field getField() {
+            return field;
+        }
+
+        public void setField(Field field) {
+            this.field = field;
+        }
+
+        public Class<?> getKlass() {
+            return klass;
+        }
+
+        public void setKlass(Class<?> klass) {
+            this.klass = klass;
+        }
+
+        public Method getMethod() {
+            return method;
+        }
+
+        public void setMethod(Method method) {
+            this.method = method;
+        }
+
+        public Class<?> getType() {
+            return type;
+        }
+
+        public void setType(Class<?> type) {
+            this.type = type;
+        }
+
+        public Type getGenericType() {
+            return genericType;
+        }
+
+        public void setGenericType(Type genericType) {
+            this.genericType = genericType;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder builder = new StringBuilder();
+
+            if (field != null) {
+                int modifiers = field.getModifiers();
+                builder.append(getModifierString(modifiers));
+                builder.append('f');
+            }
+
+            if (method != null) {
+                int modifiers = method.getModifiers();
+                builder.append(getModifierString(modifiers));
+                builder.append('m');
+            }
+            builder.append('[');
+            builder.append(getTypeString(type));
+            builder.append(']');
+            return builder.toString();
+        }
+
+        public boolean canAccess() {
+            if (field != null && Modifier.isPublic(field.getModifiers())) {
+                return true;
+            }
+            if (method != null && Modifier.isPublic(method.getModifiers())) {
+                return true;
+            }
+            return false;
+        }
+
+        public boolean fieldType() {
+            if (field != null && Modifier.isPublic(field.getModifiers())) {
+                return true;
+            }
+            return false;
+        }
+
+        public boolean methodType() {
+            if (method != null && Modifier.isPublic(method.getModifiers())) {
+                return true;
+            }
+            return false;
+        }
+    }
+
+    public static class ClassPropertyMutator {
+
+        private Class<?> klass;
+        private Class<?> type;
+        private Type genericType;
+        private Method method;
+        private Field field;
+
+        public Field getField() {
+            return field;
+        }
+
+        public void setField(Field field) {
+            this.field = field;
+        }
+
+        public Class<?> getKlass() {
+            return klass;
+        }
+
+        public void setKlass(Class<?> klass) {
+            this.klass = klass;
+        }
+
+        public Method getMethod() {
+            return method;
+        }
+
+        public void setMethod(Method method) {
+            this.method = method;
+        }
+
+        public Class<?> getType() {
+            return type;
+        }
+
+        public void setType(Class<?> type) {
+            this.type = type;
+        }
+
+        public Type getGenericType() {
+            return genericType;
+        }
+
+        public void setGenericType(Type genericType) {
+            this.genericType = genericType;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder builder = new StringBuilder();
+
+            if (field != null) {
+                int modifiers = field.getModifiers();
+                builder.append(getModifierString(modifiers));
+                builder.append('f');
+            }
+
+            if (method != null) {
+                int modifiers = method.getModifiers();
+                builder.append(getModifierString(modifiers));
+                builder.append('m');
+            }
+            builder.append('[');
+            builder.append(getTypeString(type));
+            builder.append(']');
+            return builder.toString();
+        }
+
+        public boolean canAccess() {
+            if (field != null && Modifier.isPublic(field.getModifiers())) {
+                return true;
+            }
+            if (method != null && Modifier.isPublic(method.getModifiers())) {
+                return true;
+            }
+            return false;
+        }
+
+        public boolean fieldType() {
+            if (field != null && Modifier.isPublic(field.getModifiers())) {
+                return true;
+            }
+            return false;
+        }
+
+        public boolean methodType() {
+            if (method != null && Modifier.isPublic(method.getModifiers())) {
+                return true;
+            }
+            return false;
+        }
+
+        public void fire(Object object, boolean bool) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, bool);
+            }
+            if (fieldType()) {
+                field.set(object, bool);
+            }
+        }
+
+        public void fire(Object object, byte byteValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, byteValue);
+            }
+            if (fieldType()) {
+                field.set(object, byteValue);
+            }
+        }
+
+        public void fire(Object object, short shortValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, shortValue);
+            }
+            if (fieldType()) {
+                field.set(object, shortValue);
+            }
+        }
+
+        public void fire(Object object, float floatValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, floatValue);
+            }
+            if (fieldType()) {
+                field.set(object, floatValue);
+            }
+        }
+
+        public void fire(Object object, int intValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, intValue);
+            }
+            if (fieldType()) {
+                field.set(object, intValue);
+            }
+        }
+
+        public void fire(Object object, long longValue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, longValue);
+            }
+            if (fieldType()) {
+                field.set(object, longValue);
+            }
+        }
+
+        public void fire(Object object, String string) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, string);
+            }
+            if (fieldType()) {
+                field.set(object, string);
+            }
+        }
+
+        public void fire(Object object, Object propertyObject) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+            if (methodType()) {
+                method.invoke(object, propertyObject);
+            }
+            if (fieldType()) {
+                field.set(object, propertyObject);
+            }
+        }
+    }
+
+    public static String getModifierString(int modifiers) {
+        String modifier = null;
+        if (Modifier.isPublic(modifiers)) {
+            modifier = "+";
+        } else if (Modifier.isPrivate(modifiers)) {
+            modifier = "-";
+        } else if (Modifier.isProtected(modifiers)) {
+            modifier = "#";
+        } else {
+            modifier = "%";
+        }
+        return modifier;
+    }
+
+    public static String getTypeString(Type genericType) {
+        StringBuilder builder = new StringBuilder();
+        if (genericType instanceof Class) {
+            Class<?> genericTypeClass = (Class<?>) genericType;
+            builder.append(genericTypeClass.getSimpleName());
+        } else if (genericType instanceof ParameterizedType) {
+            ParameterizedType genericParameterizedType = (ParameterizedType) genericType;
+            builder.append(getTypeString(genericParameterizedType.getRawType()));
+            Type[] innerTypes = genericParameterizedType.getActualTypeArguments();
+            builder.append('<');
+            if (innerTypes.length > 0) {
+                for (int i = 0; i < innerTypes.length - 1; i++) {
+                    builder.append(getTypeString(innerTypes[i])).append(',');
+                }
+                builder.append(getTypeString(innerTypes[innerTypes.length - 1]));
+            }
+            builder.append('>');
+        }
+        return builder.toString();
+    }
+}

File src/test/java/cc/plural/jsonij/marshal/CodecTest.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.Value;
-import cc.plural.jsonij.marshal.codec.DateJSONValueCodec;
-import cc.plural.jsonij.marshal.codec.JSONValueCodecStore;
-import cc.plural.jsonij.parser.ParserException;
-import java.io.IOException;
-import java.util.Date;
-import org.junit.After;
-import org.junit.AfterClass;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- *
- * @author jmarsden
- */
-public class CodecTest {
-
-    public CodecTest() {
-    }
-
-    @BeforeClass
-    public static void setUpClass() {
-    }
-
-    @AfterClass
-    public static void tearDownClass() {
-    }
-
-    @Before
-    public void setUp() {
-        JSONValueCodecStore.clearCodecs();
-    }
-
-    @After
-    public void tearDown() {
-    }
-
-    @Test
-    public void testCodecStoreRegister() throws JSONMarshalerException, IOException, ParserException {
-        System.out.println("testCodecStoreRegister");
-
-        JSONValueCodecStore codecStore = new JSONValueCodecStore();
-
-        assertFalse(codecStore.hasCodec(Date.class));
-
-        codecStore.registerCodec(Date.class, DateJSONValueCodec.class);
-
-        assertTrue(codecStore.hasCodec(Date.class));
-    }
-
-    @Test
-    public void testCodecStoreRegisterParent() throws JSONMarshalerException, IOException, ParserException {
-        System.out.println("testCodecStoreRegisterParent");
-
-        JSONValueCodecStore codecStore = new JSONValueCodecStore();
-
-        assertFalse(codecStore.hasCodec(Date.class));
-
-        codecStore.registerCodec(Date.class, DateJSONValueCodec.class);
-
-        assertTrue(codecStore.hasCodec(InternalDate.class));
-    }
-
-    @Test
-    public void testCodecStoreRegisterDate() throws JSONMarshalerException, IOException, ParserException {
-        System.out.println("testCodecStoreRegisterDate");
-
-        assertFalse(JavaMarshalerObjects.hasCodec(Date.class));
-
-        Date testDate = new Date();
-        Value valueNoCodec = JSONMarshaler.marshalObjectToValue(testDate);
-
-        System.out.println("Value No Codec:" + valueNoCodec);
-
-        assertFalse(JavaMarshalerObjects.hasCodec(Date.class));
-
-        JavaMarshalerObjects.registerCodec(Date.class, DateJSONValueCodec.class);
-
-        assertTrue(JavaMarshalerObjects.hasCodec(Date.class));
-
-        Value valueCodec = JSONMarshaler.marshalObjectToValue(testDate);
-
-        System.out.println("Value Codec:" + valueCodec);
-
-        assertEquals(valueCodec.toString(), "{\"time\":" + testDate.getTime() + "}");
-    }
-
-    @Test
-    public void testCodecStoreRegisterDateEncodeDecode() throws JSONMarshalerException, IOException, ParserException {
-        System.out.println("testCodecStoreRegisterDateEncodeDecode");
-
-        assertFalse(JavaMarshalerObjects.hasCodec(Date.class));
-
-        InternalDate testDate = new InternalDate();
-        Value valueNoCodec = JSONMarshaler.marshalObjectToValue(testDate);
-
-        System.out.println("Value No Codec:" + valueNoCodec);
-
-        assertFalse(JavaMarshalerObjects.hasCodec(InternalDate.class));
-
-        JavaMarshalerObjects.registerCodec(InternalDate.class, DateJSONValueCodec.class);
-
-        assertTrue(JavaMarshalerObjects.hasCodec(InternalDate.class));
-
-        Value valueCodec = JSONMarshaler.marshalObjectToValue(testDate);
-
-        System.out.println("Value Codec:" + valueCodec);
-
-        InternalDate decodeDate = DateJSONValueCodec.decode(valueCodec, InternalDate.class);
-        
-        System.out.println("Decode Codec:" + decodeDate);
-        
-        assertEquals(valueCodec.toString(), "{\"time\":" + testDate.getTime() + "}");
-    }
-
-    @Test
-    public void testDateJSONValueCodec() throws JSONMarshalerException, IOException, ParserException, InstantiationException, IllegalAccessException {
-        System.out.println("testCodecStoreRegisterDateChildEncodeDecode");
-
-        InternalDate encodeDate = new InternalDate();
-
-        System.out.println("EncodeDate:" + encodeDate);
-
-        Value value = DateJSONValueCodec.encode(encodeDate);
-
-        InternalDate decodeDate = DateJSONValueCodec.decode(value, InternalDate.class);
-
-        System.out.println("DecodeDate:" + decodeDate);
-
-        assertEquals(encodeDate, decodeDate);
-    }
-
-    public static class InternalDate extends Date {
-    }
-}
+/*
+ * 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.Value;
+import cc.plural.jsonij.marshal.codec.DateJSONValueCodec;
+import cc.plural.jsonij.marshal.codec.JSONValueCodecStore;
+import cc.plural.jsonij.parser.ParserException;
+import java.io.IOException;
+import java.util.Date;
+import org.junit.After;
+import org.junit.AfterClass;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author jmarsden
+ */
+public class CodecTest {
+
+    public CodecTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() {
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+    }
+
+    @Before
+    public void setUp() {
+        JSONValueCodecStore.clearCodecs();
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    @Test
+    public void testCodecStoreRegister() throws JSONMarshalerException, IOException, ParserException {
+        System.out.println("testCodecStoreRegister");
+
+        JSONValueCodecStore codecStore = new JSONValueCodecStore();
+
+        assertFalse(codecStore.hasCodec(Date.class));
+
+        codecStore.registerCodec(Date.class, DateJSONValueCodec.class);
+
+        assertTrue(codecStore.hasCodec(Date.class));
+    }
+
+    @Test
+    public void testCodecStoreRegisterParent() throws JSONMarshalerException, IOException, ParserException {
+        System.out.println("testCodecStoreRegisterParent");
+
+        JSONValueCodecStore codecStore = new JSONValueCodecStore();
+
+        assertFalse(codecStore.hasCodec(Date.class));
+
+        codecStore.registerCodec(Date.class, DateJSONValueCodec.class);
+
+        assertTrue(codecStore.hasCodec(InternalDate.class));
+    }
+
+    @Test
+    public void testCodecStoreRegisterDate() throws JSONMarshalerException, IOException, ParserException {
+        System.out.println("testCodecStoreRegisterDate");
+
+        assertFalse(JSONMarshaler.hasCodec(Date.class));
+
+        Date testDate = new Date();
+        Value valueNoCodec = JSONMarshaler.marshalObjectToValue(testDate);
+
+        System.out.println("Value No Codec:" + valueNoCodec);
+
+        assertFalse(JSONMarshaler.hasCodec(Date.class));
+
+        JSONMarshaler.registerCodec(Date.class, DateJSONValueCodec.class);
+
+        assertTrue(JSONMarshaler.hasCodec(Date.class));
+
+        Value valueCodec = JSONMarshaler.marshalObjectToValue(testDate);
+
+        System.out.println("Value Codec:" + valueCodec);
+
+        assertEquals(valueCodec.toString(), "{\"time\":" + testDate.getTime() + "}");
+    }
+
+    @Test
+    public void testCodecStoreRegisterDateEncodeDecode() throws JSONMarshalerException, IOException, ParserException {
+        System.out.println("testCodecStoreRegisterDateEncodeDecode");
+
+        assertFalse(JSONMarshaler.hasCodec(Date.class));
+
+        InternalDate testDate = new InternalDate();
+        Value valueNoCodec = JSONMarshaler.marshalObjectToValue(testDate);
+
+        System.out.println("Value No Codec:" + valueNoCodec);
+
+        assertFalse(JSONMarshaler.hasCodec(InternalDate.class));
+
+        JSONMarshaler.registerCodec(InternalDate.class, DateJSONValueCodec.class);
+
+        assertTrue(JSONMarshaler.hasCodec(InternalDate.class));
+
+        Value valueCodec = JSONMarshaler.marshalObjectToValue(testDate);
+
+        System.out.println("Value Codec:" + valueCodec);
+
+        InternalDate decodeDate = DateJSONValueCodec.decode(valueCodec, InternalDate.class);
+        
+        System.out.println("Decode Codec:" + decodeDate);
+        
+        assertEquals(valueCodec.toString(), "{\"time\":" + testDate.getTime() + "}");
+    }
+
+    @Test
+    public void testDateJSONValueCodec() throws JSONMarshalerException, IOException, ParserException, InstantiationException, IllegalAccessException {
+        System.out.println("testCodecStoreRegisterDateChildEncodeDecode");
+
+        InternalDate encodeDate = new InternalDate();
+
+        System.out.println("EncodeDate:" + encodeDate);
+
+        Value value = DateJSONValueCodec.encode(encodeDate);
+
+        InternalDate decodeDate = DateJSONValueCodec.decode(value, InternalDate.class);
+
+        System.out.println("DecodeDate:" + decodeDate);
+
+        assertEquals(encodeDate, decodeDate);
+    }
+
+    public static class InternalDate extends Date {
+    }
+}

File src/test/java/cc/plural/jsonij/marshal/JSONDocumentMarshalerTest.java

         JSON outputJSON = JSONMarshaler.marshalObject(config);
         System.out.println("Output JSON (no codec):" + outputJSON);
 
-        JavaMarshalerObjects.registerCodec(Class.class, ClassJSONValueCodec.class);
+        JSONMarshaler.registerCodec(Class.class, ClassJSONValueCodec.class);
 
         outputJSON = JSONMarshaler.marshalObject(config);
         System.out.println("Output JSON (codec):" + outputJSON);

File src/test/java/jsonij/legacy/marshal/Cycle.java

 package jsonij.legacy.marshal;
 
 import cc.plural.jsonij.Value;
+import cc.plural.jsonij.marshal.JSONMarshaler;
 import cc.plural.jsonij.marshal.JSONMarshalerException;
 import cc.plural.jsonij.marshal.JavaMarshaler;
 import cc.plural.jsonij.marshal.JavaMarshalerObjects;
         System.out.println(output.toJSON());
 
         System.out.println("1 nested level");
-        JavaMarshalerObjects.setCycleLevels(1);
+        JSONMarshaler.setCycleLevels(1);
         marshaler = new JavaMarshaler();
         output = marshaler.marshalObject(book);
         System.out.println(output.toJSON());
         System.out.println(output.toJSON());
 
         System.out.println("2 nested levels");
-        JavaMarshalerObjects.setCycleLevels(2);
+        JSONMarshaler.setCycleLevels(2);
         marshaler = new JavaMarshaler();
         output = marshaler.marshalObject(book);
         System.out.println(output.toJSON());