Coder Social home page Coder Social logo

Comments (2)

chibash avatar chibash commented on July 19, 2024

Multiple generic parameters are not so different from a single one.
Just build a class file as if all the parameters are of type java.lang.Object.
Then attach appropriate generic signatures to the class and the methods.

from javassist.

dyorgio avatar dyorgio commented on July 19, 2024

Hi @chibash , thank you for reply πŸ˜ƒ

Sometimes what is easy to us is hard to another people that donΒ΄t use javassist every day.

I solve my problem, trying a lot....many, many, many times...

I will put here, so if you or another dev of javassist put it on a example/tutorial file it will be cool:

Problem: retain ParametrizedType generic info at runtime for hibernate read it from AttributeConverter interface.

Solution: Use

ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("your.base.generic.enum.converter.Type");
cc.setName("someRandomName");

ClassSignature cs = new ClassSignature(null, null,
                                  // Set interface and its generic params
                                  new ClassType[]{new ClassType(AttributeConverter.class.getName(),
                                    new TypeArgument[]{
                                      new TypeArgument(new ClassType("user.enum.Type")),
                                        new TypeArgument(new ClassType("database.Type"))
                                    })});

cc.setGenericSignature(cs.encode());

// Constructor that call base class constructor with argument
CtConstructor ctConstructor = new CtConstructor(new CtClass[]{}, cc);
ctConstructor.setBody("this(" + "user.enum.Type" + ".class);");
cc.addConstructor(ctConstructor);

from javassist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.