Jackson serialization: how to ignore superclass properties

You can register a custom Jackson annotation intropector which would ignore all the properties that come from the certain super type. Here is an example: public class JacksonIgnoreInherited { public static class Base { public final String field1; public Base(final String field1) { this.field1 = field1; } } public static class Bean extends Base { … Read more

Python super() behavior not dependable

Are you reloading modules somehow in the middle of things? If so, that may explain this error. isinstance(self,DBAdminConnection) may become false after reloading modules because of the changes to memory references, apparently. Edit: if you’re running your web.py app under mod_wsgi, make sure you’re disabling autoreload: app = web.application(urls, globals(), autoreload=False)

Preventing a class from direct instantiation in Python

I would override __new__() in the base class and simply fail to instantiate at all if it’s the base class. class BaseClass: # Py3 def __new__(cls, *args, **kwargs): if cls is BaseClass: raise TypeError(f”only children of ‘{cls.__name__}’ may be instantiated”) return object.__new__(cls, *args, **kwargs) This separates concerns a little better than having it in __init__(), … Read more

implicit super constructor Person() is undefined. Must explicitly invoke another constructor?

If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is … Read more

Swift subclassing – how to override Init()

In addition to Chuck’s answer, you also have to initialize your new introduced property before calling super.init A designated initializer must ensure that all of the properties introduced by its class are initialized before it delegates up to a superclass initializer. (The Swift Programming Language -> Language Guide -> Initialization) Thus, to make it work: … Read more

How to call a superclass method using Java reflection

If you are using JDK7, you can use MethodHandle to achieve this: public class Test extends Base { public static void main(String[] args) throws Throwable { MethodHandle h1 = MethodHandles.lookup().findSpecial(Base.class, “toString”, MethodType.methodType(String.class), Test.class); MethodHandle h2 = MethodHandles.lookup().findSpecial(Object.class, “toString”, MethodType.methodType(String.class), Test.class); System.out.println(h1.invoke(new Test())); // outputs Base System.out.println(h2.invoke(new Test())); // outputs Base } @Override public String toString() … Read more

How to determine if an object is an instance of certain derived C++ class from a pointer to a base class in GDB?

Use ptype. If you use it by itself, you get the declared type of the pointer: (gdb) ptype ptr type = class SuperClass { // various members } * To get the actual type of the object pointed to, set the “print object” variable: (gdb) set print object on (gdb) ptype ptr type = /* … Read more