1. John Marsden
  2. jsonij

Commits

John Marsden  committed 7154a7c

Format Updates

  • Participants
  • Parent commits 97913aa

Comments (0)

Files changed (9)

File pom.xml

View file
     <groupId>cc.plural</groupId>
     <artifactId>jsonij</artifactId>
     <packaging>jar</packaging>
-    <version>0.3.0-SNAPSHOT</version>
+    <version>0.3.1-SNAPSHOT</version>
     <name>JSONiJ</name>
     <url>https://bitbucket.org/jmarsden/jsonij/</url>
     <properties>

File src/main/java/cc/plural/jsonij/ArrayImp.java

View file
 public class ArrayImp<E extends Value> extends Value implements java.util.List<E> {
 
     /**
-	 * Generated Serial UID
-	 */
-	private static final long serialVersionUID = -8216125868251081773L;
-	/**
-	 * Array Contents Holder
-	 */
-	protected List<E> arrayValue;
+    * Generated Serial UID
+    */
+    private static final long serialVersionUID = -8216125868251081773L;
+    /**
+    * Array Contents Holder
+    */
+    protected List<E> arrayValue;
 
     public ArrayImp() {
         arrayValue = new ArrayList<E>();

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

View file
 /**
- * Copyright (C) 2010-2011 J.W.Marsden
+ * Copyright (C) 2010-2014 J.W.Marsden
  *
  * 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
  */
 package cc.plural.jsonij;
 
-import java.io.IOException;
-import java.io.Reader;
-
 import cc.plural.jsonij.parser.ParserException;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.Reader;
 
 /**
  * JSON document class.
         /**
          * Default Constructor.
          *
-         * @param n The java.lang.Number Value.
+         * @param value The java.lang.Number Value.
          */
         public Numeric(int value) {
             super(value);

File src/main/java/cc/plural/jsonij/Value.java

View file
         }
         return result;
     }
-
+    
     /**
      * Converts the current Value into a JSON String that represents it.
      *

File src/main/java/cc/plural/jsonij/jpath/ExpressionPredicate.java

View file
 
     @Override
     public List<Value> evaluate(List<Value> values, List<Value> results) {
-
         for (Value value : values) {
             if (value.getValueType() == Value.TYPE.ARRAY) {
                 for (int j = 0; j < value.size(); j++) {
                                 String functionName = functionCondition.getFunctionName();
                                 FunctionArgument[] funtionArguments = functionCondition.getArguments();
 
-                                if(functionName.equals("regex")) {
+                                if (functionName.equals("regex")) {
                                     RegexFunction regexFunction = new RegexFunction();
                                     Value result = regexFunction.evaluate(funtionArguments, checkElement);
-                                    if(result == null) {
+                                    if (result == null) {
                                         expressionValid = false;
                                         break;
-                                    } 
+                                    }
                                 }
                             }
                         }
                     }
                 }
             } else {
-                if(value.getValueType() == Value.TYPE.OBJECT) {
+                if (value.getValueType() == Value.TYPE.OBJECT) {
 
                     boolean expressionValid = true;
                     for (ExpressionPredicateCondition condition : conditions) {
                             String functionName = functionCondition.getFunctionName();
                             FunctionArgument[] funtionArguments = functionCondition.getArguments();
 
-                            if(functionName.equals("regex")) {
+                            if (functionName.equals("regex")) {
                                 RegexFunction regexFunction = new RegexFunction();
                                 Value result = regexFunction.evaluate(funtionArguments, value);
-                                if(result != null) {
+                                if (result != null) {
                                     results.add(value);
-                                } 
+                                }
                             }
                         }
                     }
     public enum ExpressionPredicateCombineOperator {
 
         AND,
-        OR,}
+        OR,
+    }
 
     public static class ExpressionPredicateCondition {
     }
 
         @Override
         public String toString() {
-            return String.format("OperatorExpressionPredicateCondition (%s%s %s %s)", ( ( combine != null ) ? String.format("%s ", combine) : "" ), attribute, operator, value.toJSON());
+            return String.format("OperatorExpressionPredicateCondition (%s%s %s %s)", ((combine != null) ? String.format("%s ", combine) : ""), attribute, operator, value.toJSON());
         }
     }
 
             StringBuilder argumentStringBuilder = new StringBuilder();
             Object argValue = null;
             int argCount;
-            if (( argCount = Array.getLength(arguments) ) > 0) {
+            if ((argCount = Array.getLength(arguments)) > 0) {
                 for (int i = 0; i < argCount - 1; i++) {
                     argValue = arguments[i];
                     if (argValue != null) {

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

View file
                 if (value.type() == Value.TYPE.STRING) {
                     try {
                         return Class.forName(value.toString());
-                    } catch (ClassNotFoundException ex) { }
+                    } catch (ClassNotFoundException ex) {
+                        return null;
+                    }
                 }
             case UNKOWN:
             default:
-                System.out.println("Unknown Type:" + type + " " + value);
-                throw new RuntimeException("Unhandled Type " + type + " " + value);
+            //System.out.println("Unknown Type:" + type + " " + value);
+            //throw new RuntimeException("Unhandled Type " + type + " " + value);
         }
 
         return resultObject;
                 }
                 List<Object> returnList = new ArrayList();
 
-                for(int i=0;i<returnList.size();i++) {
+                for (int i = 0; i < returnList.size(); i++) {
 
                     Value value = jsonArray.get(i);
 
                 throw new RuntimeException("Beef this up");
             }
         }
-        
-        
+
+
         return null;
     }
 
                 Map<?, ?> propertyMap = marshalJSONDocumentMap((JSON.Object<CharSequence, Value>) value, mutator.getGenericType());
                 mutator.fire(object, propertyMap);
                 return;
+            case CLASS:
+                Class<?> clazz = null;
+                try {
+                    clazz = Class.forName(value.toString());
+                } catch (ClassNotFoundException ex) {
+                    Logger.getLogger(JSONDocumentMarshaler.class.getName()).log(Level.SEVERE, "Error Loading Class: {0}", new Object[] {ex.toString()});
+                }
+                mutator.fire(object, clazz);
+                return;
             case UNKOWN:
                 Object propertyUnknown = marshalJSONDocument(value, mutator.getType());
                 mutator.fire(object, propertyUnknown);

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

View file
  */
 package cc.plural.jsonij.marshal;
 
-import java.lang.reflect.Array;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 import cc.plural.jsonij.JSON;
 import cc.plural.jsonij.Value;
 import cc.plural.jsonij.marshal.codec.JSONValueCodecStore;
 import cc.plural.jsonij.reflect.ReflectType;
+import java.lang.reflect.Array;
 import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
     }
 
     public Value marshalObject(boolean[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(Boolean[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(int[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(Integer[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(char[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(double[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(Double[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(float[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(Float[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(short[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(Short[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(long[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(Long[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(String[] a) {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
     }
 
     public Value marshalObject(Object[] a) throws JSONMarshalerException {
-        int size = 0;
+        int size;
         if ((size = Array.getLength(a)) == 0) {
             return new JSON.Array<JSON.Numeric>();
         }
                 marshaledObject = marshalJavaMap(o, cycleDetector);
                 break;
             case CLASS:
-                marshaledObject = new JSON.String(o.getClass().getCanonicalName());
+                Class clazz = (Class) o;
+                marshaledObject = new JSON.String(clazz.getCanonicalName());
                 break;
             case JSON_VALUE:
                 marshaledObject = (Value) o;
     }
 
     protected Value marshalJavaBoolean(Object o) {
-        Value value = null;
+        Value value;
         boolean marshaledBoolean = (Boolean) o;
         if (marshaledBoolean) {
             value = JSON.TRUE;
     }
 
     protected Value marshalJavaNumeric(Object o) {
-        Value value = null;
+        Value value;
         Number marshaledNumber = null;
         marshaledNumber = (Number) o;
         if (marshaledNumber != null) {
     }
 
     protected Value marshalJavaEnum(Object o) {
-        Value value = null;
+        Value value;
         if (o != null) {
             String marshaledEnumeration = o.toString();
             value = new JSON.String(marshaledEnumeration);
     }
 
     protected Value marshalJavaString(Object o) {
-        Value value = null;
+        Value value;
         String marshaledString = o.toString();
         if (marshaledString != null) {
             value = new JSON.String(marshaledString);
     }
 
     protected Value marshalJavaArray(Object o, CycleDetector cycleDetector) throws JSONMarshalerException {
-        Value value = null;
+        Value value;
         if (o != null) {
             JSON.Array<Value> marshaledArray = new JSON.Array<Value>();
             int size = Array.getLength(o);

File src/main/java/cc/plural/jsonij/parser/ReaderParser.java

View file
 
 import java.io.IOException;
 
-import cc.plural.jsonij.parser.ParserException;
-import cc.plural.jsonij.parser.Position;
-
-/**
- *
- * @author openecho
- */
 public interface ReaderParser {
 
     /**

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

View file
 package cc.plural.jsonij.marshal;
 
 import cc.plural.jsonij.JSON;
-import cc.plural.jsonij.marshal.annotation.JSONName;
 import cc.plural.jsonij.marshal.codec.ClassJSONValueCodec;
 import cc.plural.jsonij.marshal.helpers.BasicTestObject;
 import cc.plural.jsonij.marshal.helpers.HandlerConfiguration;
 import cc.plural.jsonij.marshal.helpers.JSONObject;
 import cc.plural.jsonij.parser.ParserException;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
     @Test
     public void testBasicObjectClass() throws JSONMarshalerException, IOException, ParserException, IllegalAccessException, InstantiationException, ClassNotFoundException {
-BasicTestObject test = new BasicTestObject();
-test.setId(321);
-test.value = "I am a String";
-test.getClassMapping().put("Java Date Class", Date.class);
-test.getClassMapping().put("JSON Marshaller", JSONMarshaler.class);
-System.out.println(JSONMarshaler.marshalObject(test).toJSON());
+        BasicTestObject test = new BasicTestObject();
+        test.setId(321);
+        test.value = "I am a String";
+        test.getClassMapping().put("Java Date Class", Date.class);
+        test.getClassMapping().put("JSON Marshaller", JSONMarshaler.class);
+        System.out.println(JSONMarshaler.marshalObject(test).toJSON());
     }
-    
+
     @Test
     public void testMarshalHandlerClass() throws JSONMarshalerException, IOException, ParserException, IllegalAccessException, InstantiationException, ClassNotFoundException {
         System.out.println("testMarshalHandlerClass");
         handlers.put("http", JSON.class);
         handlers.put("ftp", JSONMarshaler.class);
         config.setHandlers(handlers);
-        
+
         JSON outputJSON = JSONMarshaler.marshalObject(config);
         System.out.println("Output JSON (no codec):" + outputJSON);