Jersey只从@BeanParam参数中读取第一个@QueryParam

问题描述 投票:0回答:1

我有这个Jersey POST资源:

@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Response blablabla(InputStream inputStream, 
@BeanParam ImportParams importParams) throws IOException, JAXBException, SAXException {

这是ImportParams类:

public class ImportParams {
    @QueryParam(value = "importType")
    public ImportType importType = ImportType.MERGE;

    @ApiParam("Force stop point type for all stop points in file. Useful if no modality defined in the netex file.")
    @QueryParam(value = "forceStopType")
    public StopTypeEnumeration forceStopType;

}

当我使用curl发布到资源时,只有我在URL中的问号后指定的第一个查询参数由jersey读取:

curl -XPOST -H"Content-Type: application/xml" -H"authorization: bearer $TOKEN" -d@$3  http://localhost:8585/services/stop_places/netex?forceStopType=TRAM_STATION&importType=MERGE

==> forceStopType has the right value, and importType is null

curl -XPOST -H"Content-Type: application/xml" -H"authorization: bearer $TOKEN" -d@$3  http://localhost:8585/services/stop_places/netex?importType=MERGE&forceStopType=TRAM_STATION

==> importType has the right value and forceStopType is null

我以前曾经多次使用过@BeanParam而且它曾经工作过,所以我一定会错过一些明显的东西....感谢您的帮助

java jersey jersey-2.0
1个回答
0
投票

哈哈发现了 - 愚蠢的我。当cURLing时,不得不在URL周围加上双引号:

curl -XPOST -H"Content-Type: application/xml" -H"authorization: bearer $TOKEN" -d@$3  "http://localhost:8585/services/stop_places/netex?forceStopType=TRAM_STATION&importType=MERGE"
© www.soinside.com 2019 - 2024. All rights reserved.