本文整理汇总了Java中org.springframework.web.bind.WebDataBinder.setConversionService方法的典型用法代码示例。如果您正苦于以下问题:Java WebDataBinder.setConversionService方法的具体用法?Java WebDataBinder.setConversionService怎么用?Java WebDataBinder.setConversionService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.bind.WebDataBinder
的用法示例。
在下文中一共展示了WebDataBinder.setConversionService方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initBinder
import org.springframework.web.bind.WebDataBinder; //导入方法依赖的package包/类
@Override
public void initBinder(WebDataBinder binder, WebRequest request) {
binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
if (this.directFieldAccess) {
binder.initDirectFieldAccess();
}
if (this.messageCodesResolver != null) {
binder.setMessageCodesResolver(this.messageCodesResolver);
}
if (this.bindingErrorProcessor != null) {
binder.setBindingErrorProcessor(this.bindingErrorProcessor);
}
if (this.validator != null && binder.getTarget() != null &&
this.validator.supports(binder.getTarget().getClass())) {
binder.setValidator(this.validator);
}
if (this.conversionService != null) {
binder.setConversionService(this.conversionService);
}
if (this.propertyEditorRegistrars != null) {
for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
propertyEditorRegistrar.registerCustomEditors(binder);
}
}
}
示例2: readJavaType
import org.springframework.web.bind.WebDataBinder; //导入方法依赖的package包/类
/**
* Before call to {@link ObjectMapper#readValue(java.io.InputStream, Class)}
* creates a {@link ServletRequestDataBinder} and put it to current Thread
* in order to be used by the {@link DataBinderDeserializer}.
* <p/>
* Ref: <a href=
* "http://java.dzone.com/articles/java-thread-local-%E2%80%93-how-use">When
* to use Thread Local?</a>
*
* @param javaType
* @param inputMessage
* @return
*/
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
try {
Object target = null;
String objectName = null;
// CRear el DataBinder con un target object en funcion del javaType,
// ponerlo en el thread local
Class<?> clazz = javaType.getRawClass();
if (Collection.class.isAssignableFrom(clazz)) {
Class<?> contentClazz = javaType.getContentType().getRawClass();
target = new DataBinderList<Object>(contentClazz);
objectName = "list";
}
else if (Map.class.isAssignableFrom(clazz)) {
// TODO Class<?> contentClazz =
// javaType.getContentType().getRawClass();
target = CollectionFactory.createMap(clazz, 0);
objectName = "map";
}
else {
target = BeanUtils.instantiateClass(clazz);
objectName = "bean";
}
WebDataBinder binder = new ServletRequestDataBinder(target,
objectName);
binder.setConversionService(this.conversionService);
binder.setAutoGrowNestedPaths(true);
binder.setValidator(validator);
ThreadLocalUtil.setThreadVariable(
BindingResult.MODEL_KEY_PREFIX.concat("JSON_DataBinder"),
binder);
Object value = getObjectMapper().readValue(inputMessage.getBody(),
javaType);
return value;
}
catch (IOException ex) {
throw new HttpMessageNotReadableException(
"Could not read JSON: ".concat(ex.getMessage()), ex);
}
}