retrofit.RetrofitError:无法调用没有args的公共javafx.beans.property.IntegerProperty()

时间:2016-11-03 23:32:08

标签: javafx properties retrofit

我使用retrofit 1.4.1从webserver接收带有gson的json数据,当返回类型为普通java pojo时成功,当返回类型包含JavaFX属性时失败。

服务器中的界面:

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.z.beans.Department;

@Path ("/department")
public interface DepartmentService {
    @Path ("/query")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Department query(@QueryParam("name") String name);
}

2.JavaFClient中的接口:

import com.z.beans.Department;

import retrofit.http.Body;
import retrofit.http.POST;
import retrofit.http.Query;

public interface DepartmentService {
    @POST("/department/query")
    public Department query(@Query("name") String name);
}

3. JavaFX Java pojo:

package com.z.beans;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
public class Department{
    private IntegerProperty id =  new SimpleIntegerProperty(0);
    private StringProperty name =  new SimpleStringProperty("");

    public Department() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Integer getId(){
        return this.id.get();
    }
    public void setId(Integer id){
        this.id.set(id);
    }
    public IntegerProperty IdProperty() {
        return this.id;
    }
    public String getName(){
        return this.name.get();
    }
    public void setName(String name){
        this.name.set(name);
    }
    public StringProperty NameProperty() {
        return this.name;
    }
}

4.在改造方法中:

RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(UIUtil.remotePath)
                .setErrorHandler(new CustomErrorHandler(window))
                .build();
        DepartmentService departmentService = restAdapter.create(DepartmentService.class);
        String name = "";
        name = null == name ? "" : name.trim();
        Department result = departmentService.query(name);//Failed to invoke public javafx.beans.property.IntegerProperty() with no args

0 个答案:

没有答案