1. John Marsden
  2. jsonij

Commits

John Marsden  committed 1775602

Array to List<?> Marshal

  • Participants
  • Parent commits 949f8c4

Comments (0)

Files changed (4)

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

View file
         }
     }
 
-    public List<?> marshalJSONDocumentList(JSON.Array<Value> jsonArray, Class<?> objectClass) throws JSONMarshalerException {
+    public List<?> marshalJSONDocumentList(JSON.Array<Value> jsonArray, Type type) throws JSONMarshalerException {
+        if (type instanceof ParameterizedType) {
+            ParameterizedType parameterizedType = (ParameterizedType) type;
+
+            Type[] parameterTypeArray = parameterizedType.getActualTypeArguments();
+            if (parameterTypeArray != null && parameterTypeArray.length == 1) {
+                Class<?> valueClass = null;
+                if (parameterTypeArray[0] instanceof Class) {
+                    valueClass = (Class<?>) parameterTypeArray[0];
+                } else if (parameterTypeArray[0] instanceof ParameterizedType) {
+                    ParameterizedType valueType = (ParameterizedType) parameterTypeArray[0];
+                    valueClass = (Class<?>) valueType.getRawType();
+                }
+                List<Object> returnList = new ArrayList();
+
+                for(int i=0;i<returnList.size();i++) {
+
+                    Value value = jsonArray.get(i);
+
+                    Object o = marshalJSONDocument(value, valueClass);
+                    returnList.add(o);
+                }
+
+                return returnList;
+
+            } else {
+                throw new RuntimeException("Beef this up");
+            }
+        }
+        
+        
         return null;
     }
 
                     ParameterizedType valueType = (ParameterizedType) parameterTypeArray[1];
                     valueClass = (Class<?>) valueType.getRawType();
                 }
-
-//                if(keyClass == null || valueClass == null) {
-//                    return null;
-//                }
-//                
                 Map<CharSequence, Object> returnMap = new HashMap();
 
                 Iterator<CharSequence> keySetIterator = jsonMap.keySet().iterator();

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

View file
 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;
     }
 
     @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());
+    }
+    
+    @Test
     public void testMarshalHandlerClass() throws JSONMarshalerException, IOException, ParserException, IllegalAccessException, InstantiationException, ClassNotFoundException {
         System.out.println("testMarshalHandlerClass");
         HandlerConfiguration config = new HandlerConfiguration();

File src/test/java/jsonij/legacy/JPathTest.java

View file
         Value value = path1.evaluate(json);
         System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");
 
+        
         JPath<?> path2 = jPathParser.parse("/store/book[-2]");
         path2.setRecordEvaluateTime(true);
         value = path2.evaluate(json);

File src/test/java/jsonij/legacy/JSONParserTest.java

View file
 
     public void testParseNumeric() throws IOException, ParserException {
         parser.parse("[1,2.3,0.4,-5,-5.92,0.001E1,-0.045E45,987654321]");
+        
+        
     }
 }