private Class<?> createMixInAnnotation(String[] names) {
        Class<?> clazz = null;
        clazz = proxyMixInAnnotationMap.get(StringHelper.hashCodeOfStringArray(names));
        if (clazz != null) {
            return clazz;
        }

        ClassPool pool = ClassPool.getDefault();

        // 创建代理接口
        CtClass cc = pool.makeInterface("ProxyMixInAnnotation" + System.currentTimeMillis()
                + proxyIndex++);

        ClassFile ccFile = cc.getClassFile();
        ConstPool constpool = ccFile.getConstPool();

        // create the annotation
        AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
                AnnotationsAttribute.visibleTag);
        // 创建JsonIgnoreProperties注解
        Annotation jsonIgnorePropertiesAnnotation = new Annotation(
                JsonIgnoreProperties.class.getName(), constpool);

        BooleanMemberValue ignoreUnknownMemberValue = new BooleanMemberValue(false, constpool);

        ArrayMemberValue arrayMemberValue = new ArrayMemberValue(constpool);// value的数组成员

        Collection<MemberValue> memberValues = new HashSet<MemberValue>();
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            StringMemberValue memberValue = new StringMemberValue(constpool);// 将name值设入注解内
            memberValue.setValue(name);
            memberValues.add(memberValue);
        }
        arrayMemberValue.setValue(memberValues.toArray(new MemberValue[]{}));

        jsonIgnorePropertiesAnnotation.addMemberValue("value", arrayMemberValue);
        jsonIgnorePropertiesAnnotation.addMemberValue("ignoreUnknown", ignoreUnknownMemberValue);

        attr.addAnnotation(jsonIgnorePropertiesAnnotation);
        ccFile.addAttribute(attr);

        // generate the class
        try {
            clazz = cc.toClass();
            proxyMixInAnnotationMap.put(StringHelper.hashCodeOfStringArray(names), clazz);
            // JsonIgnoreProperties ignoreProperties = (JsonIgnoreProperties)
            // clazz
            // .getAnnotation(JsonIgnoreProperties.class);

            // EntityHelper.print(ignoreProperties);
            //
            // EntityHelper.print(clazz);

            // try {
            // Object instance = clazz.newInstance();
            // EntityHelper.print(instance);
            //
            // } catch (InstantiationException e) {
            // e.printStackTrace();
            // } catch (IllegalAccessException e) {
            // e.printStackTrace();
            // }
        } catch (CannotCompileException e) {
            e.printStackTrace();
        }

        // right
        // mthd.getMethodInfo().addAttribute(attr);

        return clazz;

    }
private Class<?> createMixInAnnotation(String[] names) {
        Class<?> clazz = null;
        clazz = proxyMixInAnnotationMap.get(StringHelper.hashCodeOfStringArray(names));
        if (clazz != null) {
            return clazz;
        }

        ClassPool pool = ClassPool.getDefault();

        
        CtClass cc = pool.makeInterface("ProxyMixInAnnotation" + System.currentTimeMillis()
                + proxyIndex++);

        ClassFile ccFile = cc.getClassFile();
        ConstPool constpool = ccFile.getConstPool();

        
        AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
                AnnotationsAttribute.visibleTag);
        
        Annotation jsonIgnorePropertiesAnnotation = new Annotation(
                JsonIgnoreProperties.class.getName(), constpool);

        BooleanMemberValue ignoreUnknownMemberValue = new BooleanMemberValue(false, constpool);

        ArrayMemberValue arrayMemberValue = new ArrayMemberValue(constpool);

        Collection<MemberValue> memberValues = new HashSet<MemberValue>();
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            StringMemberValue memberValue = new StringMemberValue(constpool);
            memberValue.setValue(name);
            memberValues.add(memberValue);
        }
        arrayMemberValue.setValue(memberValues.toArray(new MemberValue[]{}));

        jsonIgnorePropertiesAnnotation.addMemberValue("value", arrayMemberValue);
        jsonIgnorePropertiesAnnotation.addMemberValue("ignoreUnknown", ignoreUnknownMemberValue);

        attr.addAnnotation(jsonIgnorePropertiesAnnotation);
        ccFile.addAttribute(attr);

        
        try {
            clazz = cc.toClass();
            proxyMixInAnnotationMap.put(StringHelper.hashCodeOfStringArray(names), clazz);
            
            
            

            
            
            

            
            
            
            
            
            
            
            
            
        } catch (CannotCompileException e) {
            e.printStackTrace();
        }

        
        

        return clazz;

    }
private Class < ? > createMixInAnnotation ( String [ ] names ) { Class < ? > clazz = null ; clazz = proxyMixInAnnotationMap . get ( StringHelper . hashCodeOfStringArray ( names ) ) ; if ( clazz != null ) { return clazz ; } ClassPool pool = ClassPool . getDefault ( ) ; // 创建代理接口 CtClass cc = pool . makeInterface ( "ProxyMixInAnnotation" + System . currentTimeMillis ( ) + proxyIndex ++ ) ; ClassFile ccFile = cc . getClassFile ( ) ; ConstPool constpool = ccFile . getConstPool ( ) ; // create the annotation AnnotationsAttribute attr = new AnnotationsAttribute ( constpool , AnnotationsAttribute . visibleTag ) ; // 创建JsonIgnoreProperties注解 Annotation jsonIgnorePropertiesAnnotation = new Annotation ( JsonIgnoreProperties . class . getName ( ) , constpool ) ; BooleanMemberValue ignoreUnknownMemberValue = new BooleanMemberValue ( false , constpool ) ; ArrayMemberValue arrayMemberValue = new ArrayMemberValue ( constpool ) ; // value的数组成员 Collection < MemberValue > memberValues = new HashSet < MemberValue > ( ) ; for ( int i = 0 ; i < names . length ; i ++ ) { String name = names [ i ] ; StringMemberValue memberValue = new StringMemberValue ( constpool ) ; // 将name值设入注解内 memberValue . setValue ( name ) ; memberValues . add ( memberValue ) ; } arrayMemberValue . setValue ( memberValues . toArray ( new MemberValue [ ] { } ) ) ; jsonIgnorePropertiesAnnotation . addMemberValue ( "value" , arrayMemberValue ) ; jsonIgnorePropertiesAnnotation . addMemberValue ( "ignoreUnknown" , ignoreUnknownMemberValue ) ; attr . addAnnotation ( jsonIgnorePropertiesAnnotation ) ; ccFile . addAttribute ( attr ) ; // generate the class try { clazz = cc . toClass ( ) ; proxyMixInAnnotationMap . put ( StringHelper . hashCodeOfStringArray ( names ) , clazz ) ; // JsonIgnoreProperties ignoreProperties = (JsonIgnoreProperties) // clazz // .getAnnotation(JsonIgnoreProperties.class); // EntityHelper.print(ignoreProperties); // // EntityHelper.print(clazz); // try { // Object instance = clazz.newInstance(); // EntityHelper.print(instance); // // } catch (InstantiationException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } } catch ( CannotCompileException e ) { e . printStackTrace ( ) ; } // right // mthd.getMethodInfo().addAttribute(attr); return clazz ; }
创建jackson的代理注解接口类 <br>
2013-10-25 上午11:59:50

@param names 要生成的字段
@return 代理接口类
创建jackson的代理注解接口类 <br > 2013 - 10 - 25 上午11 : 59 : 50