Search in sources :

Example 1 with StringToOpenTypeConverter

use of org.jolokia.converter.object.StringToOpenTypeConverter in project fabric8 by jboss-fuse.

the class JSONTypeGenerator method toOpenData.

public static Object toOpenData(OpenType<?> otype, ClassLoader classLoader, Object value) throws OpenDataException {
    Object result;
    if (otype instanceof CompositeType && value instanceof JSONObject) {
        StringToOpenTypeConverter converter = converters.getToOpenTypeConverter();
        result = converter.convertToObject(otype, value);
    } else if (otype instanceof TabularType && value instanceof JSONObject) {
        StringToOpenTypeConverter converter = converters.getToOpenTypeConverter();
        result = converter.convertToObject(otype, value);
    } else if (otype instanceof ArrayType && value instanceof JSONArray) {
        StringToOpenTypeConverter converter = converters.getToOpenTypeConverter();
        result = converter.convertToObject(otype, value);
    } else {
        result = OpenTypeGenerator.toOpenData(otype, value);
    }
    boolean isAssignable = result == null || otype.isValue(result);
    IllegalStateAssertion.assertTrue(isAssignable, "Value " + result + " is not a value of: " + otype);
    return result;
}
Also used : ArrayType(javax.management.openmbean.ArrayType) JSONObject(org.json.simple.JSONObject) TabularType(javax.management.openmbean.TabularType) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) StringToOpenTypeConverter(org.jolokia.converter.object.StringToOpenTypeConverter) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

ArrayType (javax.management.openmbean.ArrayType)1 CompositeType (javax.management.openmbean.CompositeType)1 TabularType (javax.management.openmbean.TabularType)1 StringToOpenTypeConverter (org.jolokia.converter.object.StringToOpenTypeConverter)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1