私は基本的にスティーブンCの助言に従うことでそれを理解することができましたが、他の誰かが同じボートに入っている場合には、さらに詳しい情報を投稿すると思いました。まず、私が実際にジャージーから始め、背中のいくつかのセクションを案内し、特にこの1:もちろん、私はjavax.ws.rs.client用ジャージーを使用していますが、私はJSONのデシリアライゼーションを行うにはGensonを使用しています
https://jersey.java.net/documentation/latest/user-guide.html#d0e6825
。それが作成された後、次のように、このクライアントに登録されます
public class BTCEURTradeMessageBodyReader
implements MessageBodyReader<BTCEURTrades> {
final org.slf4j.Logger logger =
LoggerFactory.getLogger(BTCEURTradeMessageBodyReader.class);
@Override
public boolean isReadable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
logger.info("isReadable being checked for: {} and media type: {}", type, mediaType);
return type == BTCEURTrades.class;
}
@Override
public BTCEURTrades readFrom(Class<BTCEURTrades> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
logger.info("readFrom being called for: {}", type);
BTCEURTrades btceurTrades;
try {
btceurTrades = new Genson().deserialize(entityStream, type);
} catch(Exception e) {
logger.error("Error processing JSON reponse.", e);
throw new ProcessingException("Error processing JSON reponse.");
}
return btceurTrades;
}
}
:
client = ClientBuilder.newClient();
client.register(BTCEURTradeMessageBodyReader.class);
はどのようにあなたはそれが正しいJSONである知っている結果として、私はMessageBodyReaderのを実装するために以下のクラスを実装していますデータ?生の反応を見ましたか?サーバー側で何らかのエラーが発生したため、HTMLページが出力される可能性があります。サーバーログでエラーが発生しましたか? –
データを取得し、ヘッダを置き換えてさらに処理することができます。しかし、データを取得するだけで、ヘッダーを無視し、jsonオブジェクトに解析するほうが簡単だと思います。 –
Chrome RestClient拡張機能を使用してサービスに手動でアクセスしているので正しいことが分かります。 –