I'm trying to dynamically create a class which extends a class ServerPing, inside this class there is a static class called Serializer, I want to override its method "a" and returns my own JsonElement. The problem is that I don't know how to edit a static class inside another class using bytebuddy.
Here is what it could look like (but defineClassInside doesn't exist):
Class<?> serverPingSerializerClone = new ByteBuddy()
.subclass(serverPingClass)
.defineClassInside("Serializer",
new ByteBuddy().subclass(ServerPing.Serializer.class)
.method(ElementMatchers.named("a")
.and(ElementMatchers.returns(JsonElement.class)
.and(ElementMatchers.takesArguments(3))))
.intercept(FixedValue.value(exampleResponse))
.make())
.make()
.load(Core.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();```
Aucun commentaire:
Enregistrer un commentaire