I have an interface in which I want to provide a default method to Serialize the inherited classes. I use a JsonSerializer<T>
class to do serialization.
The method looks like:
public interface A
{
public default String write()
{
new JsonSerializer</*Inherited class type*/>();
// I've tried new JsonSerializer<this.getClass()>(); - Doesn't work
}
}
public class AX implements A
{
}
So when I instantiate AX, I want to use the write method to serialize AX
AX inst = new AX();
String instSerialized = inst.write();
I need to pass the type of AX to the write method in A. is this possible?