String xml = ResourceUtils.find(contextClass, resourceName);
if (xml != null) {
return JaxbHelper.deserializeXmlObject(xml, clazz);
}
} catch (Exception e) {
throw new OpsException("Error reading resource: " + resourceName, e);
}
}
{
String resourceName = key + ".json";
try {
String json = ResourceUtils.find(contextClass, resourceName);
if (json != null) {
ObjectMapper mapper = new ObjectMapper();
// Use JAXB annotations
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper = mapper.setAnnotationIntrospector(introspector);
mapper = mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
mapper = mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper = mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
if (!json.startsWith("{")) {
// Be tolerant
json = "{ " + json + "}";
// json = jsonHelper.wrapJson(json);
}
return mapper.readValue(json, clazz);
// return jsonHelper.unmarshal(json);
}
} catch (Exception e) {
throw new OpsException("Error reading resource: " + resourceName, e);
}
}
return null;
}