Package com.firefly.utils.json.parser

Examples of com.firefly.utils.json.parser.CollectionParser


              if(types2.length != 1)
                throw new JsonException("not support the " + method);
             
              Type elementType = types2[0];
              parserMetaInfo.setType(ComplexTypeParser.getImplClass(type));
              parserMetaInfo.setParser(new CollectionParser(elementType));
            } else if (Map.class.isAssignableFrom(type)) { // Map元信息构造
              Type[] types = method.getGenericParameterTypes();
              if(types.length != 1 || !(types[0] instanceof ParameterizedType))
                throw new JsonException("not support the " + method);
             
              ParameterizedType paramType = (ParameterizedType) types[0];
              Type[] types2 = paramType.getActualTypeArguments();
              if(types2.length != 2)
                throw new JsonException("not support the " + method);
             
              Type key = types2[0];
              if (!((key instanceof Class) && key == String.class))
                throw new JsonException("not support the " + method);
             
              Type elementType = types2[1];
              parserMetaInfo.setType(ComplexTypeParser.getImplClass(type));
              parserMetaInfo.setParser(new MapParser(elementType));
            } else { // 获取对象、枚举或者数组Parser
              parserMetaInfo.setType(type);
              parserMetaInfo.setParser(ParserStateMachine.getParser(type));
            }
            fieldSet.add(parserMetaInfo);
    }
   
    for(Field field : clazz.getFields()) { // public字段反序列化构造
      if(Modifier.isTransient(field.getModifiers()) || field.isAnnotationPresent(Transient.class) || Modifier.isStatic(field.getModifiers()))
        continue;
     
      field.setAccessible(true);
     
      ParserMetaInfo parserMetaInfo = new ParserMetaInfo();
            parserMetaInfo.setPropertyNameString(field.getName());
            parserMetaInfo.setPropertyInvoke(new FieldInvoke(field));
           
            Class<?> type = field.getType();
            if (Collection.class.isAssignableFrom(type)) {
              Type fieldType = field.getGenericType();
              if(!(fieldType instanceof ParameterizedType))
                throw new JsonException("not support the " + field);
             
              ParameterizedType paramType = (ParameterizedType)fieldType;
              Type[] types2 = paramType.getActualTypeArguments();
              if(types2.length != 1)
                throw new JsonException("not support the " + field);
             
              Type elementType = types2[0];
              parserMetaInfo.setType(ComplexTypeParser.getImplClass(type));
              parserMetaInfo.setParser(new CollectionParser(elementType));
            } else if (Map.class.isAssignableFrom(type)) { // Map元信息构造
              Type fieldType = field.getGenericType();
              if(!(fieldType instanceof ParameterizedType))
                throw new JsonException("not support the " + field);
             
View Full Code Here


    ParserMetaInfo p = pp[0];
    Assert.assertThat(p.getType().getName(), is(ArrayList.class.getName()));
   
    Parser parser = p.getParser();
    if(parser instanceof CollectionParser) {
      CollectionParser colp = (CollectionParser) parser;
      p = colp.getElementMetaInfo();
      Assert.assertThat(p.getType().getName(), is(LinkedList.class.getName()));
    }
   
    parser = p.getParser();
    if(parser instanceof CollectionParser) {
      CollectionParser colp = (CollectionParser) parser;
      p = colp.getElementMetaInfo();
      Assert.assertThat(p.getType().getName(), is(SimpleObj.class.getName()));
    }
  }
View Full Code Here

 
  public static void test(ParserMetaInfo p) {
    System.out.println(p.getType());
    Parser parser = p.getParser();
    if(parser instanceof CollectionParser) {
      CollectionParser colp = (CollectionParser) parser;
      test(colp.getElementMetaInfo());
    }
  }
View Full Code Here

TOP

Related Classes of com.firefly.utils.json.parser.CollectionParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.