首页 > 解决方案 > 解决了 Handler 执行引起的异常

问题描述

处理程序执行导致的已解决异常:org.springframework.http.converter.HttpMessageNotReadableException:无法读取文档:无法反序列化 java.lang.String[] 的实例超出 VALUE_STRING 令牌

2019-02-26 13:47:12.697 WARN 2510 --- [nio-9009-exec-8] .wsmsDefaultHandlerExceptionResolver:无法读取 HTTP 消息:org.springframework.http.converter.HttpMessageNotReadableException:无法读取文档:不能从 VALUE_STRING 令牌中反序列化 java.lang.String[] 的实例

在 [来源:(PushbackInputStream);行:1,列:83](通过参考链:ru.valyaeva.marathon.model.User["roles"]);嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize an instance of java.lang.String[] out of VALUE_STRING token

在 [来源:(PushbackInputStream);行:1,列:83](通过参考链:ru.valyaeva.marathon.model.User["roles"])

使用 angularjs 时出现此错误,我尝试在作为数组的角色字段中将值作为数组传输,但有些地方不正确

 <div class="bloc" >
    <select ng-model="user.roles">
        <option value= {"ROLE_USER"}>ROLE_USER</option>
        <option value= {"ROLE_SUPPORT"} >ROLE_SUPPORT</option>
        <option value={"ROLE_ADMIN"} >ROLE_ADMIN</option>
    </select>
</div>

我只是无法将此值传递到此字段,也许我错误地传递了要保存在角色字段中的值?

标签: angularjsspring

解决方案


<div class="bloc" >
<select ng-model="role" ng-change="selectRole()">
    <option ng-value="ROLE_USER">ROLE_USER</option>
    <option ng-value="ROLE_SUPPORT">ROLE_SUPPORT</option>
    <option ng-value="ROLE_ADMIN">ROLE_ADMIN</option>
</select>

$scope.role = undefined;


        $scope.selectRole = function() {
            $scope.user.roles = [$scope.role];
        }

这解决了我的错误


推荐阅读