Jersey2客户端列表映射

时间:2018-01-16 20:43:57

标签: java json jackson jersey-2.0 jersey-client

我正在尝试使用Jersey和jackson mapper开发一个休息客户端来进行对象映射。我收到了以下json回复:

{
    "currentPage": 0,
    "pageSize": 15,
    "totalResults": 1,
    "sortDirection": "",
    "orderBy": "",
    "data": [
        [
            1,
            "ingredient",
            3,
            "former",
            4,
            "nestle",
            5,
            "fish",
            true
        ]
    ]
}

所以问题出现在我尝试映射服务响应时,我得到了所有的值,但是"数据"字段,来自null。这是我正在进行通话的代码块:

public PageDTO<IngredienteBusquedaDTO> findIngredientesPaged(final IngredienteBusquedaCriteria criteria,
        final String token) {

    Client sslClient = null;
    try {
        sslClient = new SSLJerseyClient().getClient();

    } catch (KeyManagementException | NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    return sslClient
            .register(JacksonFeature.class)
            .target("https://192.168.11.6:8442/servicios/ws/")
            .path("ingrediente/paged")
            .request(MediaType.APPLICATION_JSON)
            .header("Authorization", token)
            .post(Entity.entity(criteria, MediaType.APPLICATION_JSON))
            .readEntity(new GenericType<PageDTO<IngredienteBusquedaDTO>>() {
            });
}

PageDTO类可参数化:

@Produces("application/json")
@JsonAutoDetect
public class PageDTO<T> implements Serializable {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 5491202093571112081L;

    /** The current page. */
    private Integer currentPage;

    /** The page size. */
    private Integer pageSize;

    /** The total results. */
    private Integer totalResults;

    /** The sort direction. */
    private String sortDirection;

    /** The order by. */
    private String orderBy;

    /** The data. */
    @JsonProperty
    private List<T> data;

getters and setters...

IngredienteBusquedaDTO是从服务发送的对象的精确副本:

public class IngredienteBusquedaDTO implements Serializable {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 7827829548387723259L;

    /** The id ingrediente. */
    private Long idIngrediente;

    /** The descripcion. */
    private String descripcion;

    /** The id proveedor. */
    private Long idProveedor;

    /** The descripcion proveedor. */
    private String descripcionProveedor;

    /** The id tipo ingrediente. */
    private Short idTipoIngrediente;

    /** The descripcion tipo ingrediente. */
    private String descripcionTipoIngrediente;

    /** The salsa. */
    private boolean salsa;

getters and setters

有关进展情况的任何想法?在此先感谢!!!

0 个答案:

没有答案