mode = bindingMode.name();
}
if (mode == null || "off".equals(mode)) {
// binding mode is off, so create a off mode binding processor
return new RestBindingProcessor(null, null, null, null, consumes, produces, mode);
}
// setup json data format
String name = context.getRestConfiguration().getJsonDataFormat();
if (name == null) {
name = "json-jackson";
}
DataFormat json = context.resolveDataFormat(name);
DataFormat outJson = context.resolveDataFormat(name);
// is json binding required?
if (mode.contains("json") && json == null) {
throw new IllegalArgumentException("JSon DataFormat " + name + " not found.");
}
if (json != null) {
Class<?> clazz = null;
if (type != null) {
String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
clazz = context.getClassResolver().resolveMandatoryClass(typeName);
}
if (clazz != null) {
IntrospectionSupport.setProperty(context.getTypeConverter(), json, "unmarshalType", clazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), json, "useList", type.endsWith("[]"));
}
setAdditionalConfiguration(context, json);
context.addService(json);
Class<?> outClazz = null;
if (outType != null) {
String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
outClazz = context.getClassResolver().resolveMandatoryClass(typeName);
}
if (outClazz != null) {
IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "unmarshalType", outClazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "useList", outType.endsWith("[]"));
}
setAdditionalConfiguration(context, outJson);
context.addService(outJson);
}
// setup xml data format
name = context.getRestConfiguration().getXmlDataFormat();
if (name == null) {
name = "jaxb";
}
DataFormat jaxb = context.resolveDataFormat(name);
DataFormat outJaxb = context.resolveDataFormat(name);
// is xml binding required?
if (mode.contains("xml") && jaxb == null) {
throw new IllegalArgumentException("XML DataFormat " + name + " not found.");
}
if (jaxb != null) {
Class<?> clazz = null;
if (type != null) {
String typeName = type.endsWith("[]") ? type.substring(0, type.length() - 2) : type;
clazz = context.getClassResolver().resolveMandatoryClass(typeName);
}
if (clazz != null) {
JAXBContext jc = JAXBContext.newInstance(clazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), jaxb, "context", jc);
}
if (context.getRestConfiguration().getDataFormatProperties() != null) {
IntrospectionSupport.setProperties(context.getTypeConverter(), jaxb, context.getRestConfiguration().getDataFormatProperties());
}
setAdditionalConfiguration(context, jaxb);
context.addService(jaxb);
Class<?> outClazz = null;
if (outType != null) {
String typeName = outType.endsWith("[]") ? outType.substring(0, outType.length() - 2) : outType;
outClazz = context.getClassResolver().resolveMandatoryClass(typeName);
}
if (outClazz != null) {
JAXBContext jc = JAXBContext.newInstance(outClazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), outJaxb, "context", jc);
} else if (clazz != null) {
// fallback and use the context from the input
JAXBContext jc = JAXBContext.newInstance(clazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), outJaxb, "context", jc);
}
setAdditionalConfiguration(context, outJaxb);
context.addService(outJaxb);
}
return new RestBindingProcessor(json, jaxb, outJson, outJaxb, consumes, produces, mode);
}