4

タイプLongの JAX-RS @PathParamを渡す可能性があることをチュートリアル (Jersey) で見ました。

しかし、RESTEasy でこれを実行しようとすると、エラーが発生します。

 21:50:32,353 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-15) failed to execute: javax.ws.rs.NotSupportedException: Could not find message body reader for type: long of content type: */*
    at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java:52)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73)

整数でテストしましたが、動作しません...

22:14:45,590 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-18) failed to execute: javax.ws.rs.NotSupportedException: Could not find message body reader for type: class java.lang.Integer of content type: */*
at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java:52)

さらに、この ID 値を文字列として取得し、Long.valueOf(String s)またはLong.parseLong(String s)を使用して Long に変換しようとしていますが、どちらの場合もエラーが発生します

Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:601)
at java.lang.Long.parseLong(Long.java:631)
at pl.salonea.jaxrs.UserAccountResource.getUserAccount(UserAccountResource.java:41)

これは、私の Web サービス リソース メソッドのコードです。

@GET
@Path("/{userId}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public UserAccount getUserAccount(@PathParam("userId") String userId) {

    return userAccountFacade.find(Long.parseLong(userId));
}

解決した

インポートが不適切で、javax.ws.rs.PathParam;をインポートできません。、しかし、WebソケットPathParamからの何か... IntelliJの自動インポートをリレーしただけで、それが間違っていることはわかりませんでした。

4

0 に答える 0