Subclassing Body (patch design query)

Hi,

TL;DR How would one create a Body subclass instead of a Body?
Especially in JBox2D (Java) but also in the original (C++).
I'm working on a patch for DartBox2D (the Dart version) and want to keep it as similar as possible to any existing solution.

In case I'm approaching the wrong way, I'll explain my need:
I wish to have some logic run when a Body is put to sleep (setAwake(false)) -- specifically, I switch it to a STATIC Body since it won't move again in my game (and this seems efficient).

My approach:
At least in the Java and Dart versions (the Dart version is a direct port of the Java) and AFAICT in the C++ version, there is no event dispatched (etc) here so my solution is subclassing Body (with extra logic in setAwake()) then modifying Box2D (my patch) to accept a BodyFactory on World (which, when not supplied, defaults to one that simply builds a Body as the current code). Since I my game builds both SleepyBody and regular ones, I include a switch in my implementation of BodyFactory to choose which to make before my call to createBody() which I invoke through a reference to my SleepyBodyFactory. (yes, I'm aware of parallelism risks -- not a problem in DartBox2D.)

All questions or redirects welcome (perhaps I should post outside the JBox2D sub-forum?)

If not presently viable but considered useful, should I try for patches to other versions?

TIA, Rupert.

Original thread: https://box2d.org/forum/viewtopic.php?t=8856