views:

19

answers:

0

I have some types like this:

public interface Numbering {
    List<NumberingComponent> getComponents();
}

public interface NumberingComponent {
    Object getValue();
}

public interface StringNumberingComponent extends NumberingComponent {
    String getValue();
}

public interface IntegerNumberingComponent extends NumberingComponent {
    Integer getValue();
}

This is all well and good, unless you try to register an MXBean which happens to use this type, and you get:

...top of exception chain omitted ...
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: class com.acme.NumberingComponent
    at com.sun.jmx.mbeanserver.OpenConverter.openDataException(OpenConverter.java:1411)
    at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:264)
    at com.sun.jmx.mbeanserver.OpenConverter.makeArrayOrCollectionConverter(OpenConverter.java:315)
    at com.sun.jmx.mbeanserver.OpenConverter.makeParameterizedConverter(OpenConverter.java:393)
    at com.sun.jmx.mbeanserver.OpenConverter.makeConverter(OpenConverter.java:296)
    at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:262)
    ... 57 more
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: interface java.io.Serializable
    at com.sun.jmx.mbeanserver.OpenConverter.openDataException(OpenConverter.java:1411)
    at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:264)
    at com.sun.jmx.mbeanserver.OpenConverter.makeCompositeConverter(OpenConverter.java:467)
    at com.sun.jmx.mbeanserver.OpenConverter.makeConverter(OpenConverter.java:293)
    at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:262)
    ... 61 more
Caused by: javax.management.openmbean.OpenDataException: Can't map java.io.Serializable to an open data type
    at com.sun.jmx.mbeanserver.OpenConverter.makeCompositeConverter(OpenConverter.java:454)
    at com.sun.jmx.mbeanserver.OpenConverter.makeConverter(OpenConverter.java:293)
    at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:262)
    ... 64 more

Strings and integers are representable in JMX but Object isn't, as at least one getter needs to be present on the class for it to recognise it as a usable type. I know that any attempt to add an abstraction layer in is not going to help, because NumberingComponent itself is already such a layer. The original version of the interfaces had generics in there as well, but I removed them to keep it simpler, and it fails in the same way with or without them.

Is there some other way I can go about mapping this to a composite type? I googled the exception message, and got essentially no hits at all. (!!)