AngularJs $ http Запрос запроса для сопоставления JPA OneToOne возвращает строку вместо JSON данных - PullRequest
0 голосов
/ 02 мая 2020

здесь html в AngularJs материалах

    <div layout="row">
        <md-input-container class="md-block" flex="100">
        <label>Select Country</label>
            <md-select name="type" ng-model="newDatum.country" >
                <md-option ng-repeat="c in country" value="{{c}}">{{c.name}}</md-option>
            </md-select>
      </md-input-container>
    </div>
    <md-button style="width:100%" type="submit" ng-click="createDatum(newDatum)" class="md-raised md-primary">
        <md-icon class="md-size-3x">arrow_forward</md-icon>&nbsp;&nbsp;&nbsp;Create
    </md-button>

здесь javascript

    $scope.createDatum= function(datum){
            $http({
            method : "POST",
            url : "api/address",
            data : angular.toJson(datum),
            headers : {
                "Content-Type" : "application/json"
            }
        }).then(function(response){
            $mdDialog.show($mdDialog.alert()
                .title('Create \''+datum.contactPersonName+'\' Succesfull!')
                .textContent('Here you have successfully create this \''+datum.contactPersonName.toLowerCase()+'\' configuration!')
                .ok('Ok'));
            $scocontactPersonNamehowProgressBar = false;
            $scope.getAllData();
        }, function(reason){
            $mdDialog.show($mdDialog.alert()
                .title('Create \''+datum.contactPersonName+'\' Error!')
                .textContent('Here you have got error to create this \''+datum.contactPersonName.toLowerCase()+'\' configuration! '+reason.data)
                .ok('Ok'));
            $scope.showProgressBar = false;
            $scope.error_message = reason.data;
        });}

Java отображение класса сущности

@OneToOne(cascade = CascadeType.MERGE)
@JoinTable(name = "address_country", joinColumns = @JoinColumn(name = "address_id"), inverseJoinColumns = @JoinColumn(name = "country_id"))
private Country country;

Java Ошибка компилятора

2020-05-02 15:39:53.691 WARN 5083 --- [nio-8080-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `com.zero.zerodefinition.country.Country` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"id":4,"name":"AMERICAN SAMOA","niceName":"American Samoa","countryCode":"AS","phoneCode":"1684","iso3":"ASM","numCode":"16"}'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.zero.zerodefinition.country.Country` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"id":4,"name":"AMERICAN SAMOA","niceName":"American Samoa","countryCode":"AS","phoneCode":"1684","iso3":"ASM","numCode":"16"}') at [Source: (PushbackInputStream); line: 1, column: 227] (through reference chain: com.zero.zerodefinition.address.Address["country"])]

Ошибка браузера

{"timestamp":"2020-05-02T09:39:53.692+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot construct instance of `com.zero.zerodefinition.country.Country` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{\"id\":4,\"name\":\"AMERICAN SAMOA\",\"niceName\":\"American Samoa\",\"countryCode\":\"AS\",\"phoneCode\":\"1684\",\"iso3\":\"ASM\",\"numCode\":\"16\"}'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.zero.zerodefinition.country.Country` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{\"id\":4,\"name\":\"AMERICAN SAMOA\",\"niceName\":\"American Samoa\",\"countryCode\":\"AS\",\"phoneCode\":\"1684\",\"iso3\":\"ASM\",\"numCode\":\"16\"}')\n at [Source: (PushbackInputStream); line: 1, column: 227] (through reference chain: com.zero.zerodefinition.address.Address[\"country\"])","path":"/zerodefinition/api/address"}

как решить эту проблему! Есть ли проблема с отображением спящего режима? Почему это не преобразуется в json вставленную строку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...