java - 泽西 MessageBodyProviderNotFoundException
问题描述
我有一堂课:
package com.clevergift.services.payment;
import com.github.woki.payments.adyen.model.*;
import com.google.gson.annotations.SerializedName;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.HashMap;
import java.util.Map;
@XmlRootElement
public class CGPaymentRequest {
@SerializedName("amount")
private Amount amount;
@SerializedName("merchantAccount")
private String merchantAccount;
@SerializedName("reference")
private String reference;
@SerializedName("additionalData")
private Map<String, String> additionalData = new HashMap<>();
// THIS IS SUPPOSED TO SOLVE THE PROBLEM
public CGPaymentRequest() {
}
public void setAdditionalData(Map<String, String> additionalData) {
this.additionalData = additionalData;
}
public Map<String, String> getAdditionalData() {
return additionalData;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getReference() {
return reference;
}
public void setMerchantAccount(String merchantAccount) {
this.merchantAccount = merchantAccount;
}
public String getMerchantAccount() {
return merchantAccount;
}
public void setAmount(Amount amount) {
this.amount = amount;
}
public Amount getAmount() {
return amount;
}
}
我在这里遇到了一个 API 端点:
Client client = ClientBuilder.newClient();
WebTarget webTarget
= client.target(TESTING_PAYS_URL + "authorise");
Invocation.Builder invocationBuilder
= webTarget.request(APPLICATION_JSON_TYPE);
PaymentResponse paymentResponse = invocationBuilder
.post(Entity.entity(cgPaymentRequest, MediaType.APPLICATION_JSON), PaymentResponse.class);
这在本地工作得很好。
在我的 build.gradle 文件中,我有:
// https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.6'
奇怪的是,当我在 AWS Elastic Beanstalk 上运行它时,我得到了错误:
org.glassfish.jersey.message.internal.WriterInterceptorExecutor: MessageBodyWriter not found for media type=application/json, type=class com.clevergift.services.payment.CGPaymentRequest, genericType=class com.clevergift.services.payment.CGPaymentRequest.
我尝试了这个解决方案(添加一个空的构造函数)https://stackoverflow.com/a/33756603/1246159。然而仍然得到同样的错误。
我还尝试添加:
// https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.28'
然而仍然得到同样的错误。我不确定接下来我可以尝试什么....
解决方案
推荐阅读
- android - 使用 AndroidNetworking.upload() 收到错误请求
- java - 如何阻止 JPA 存储库投影摘录返回多对多关系上的嵌入式列表
- database - ERD 的问题
- c# - 我如何在 linq 中使用 2 条件
- java - 从 Athena 查询执行 ID 获取输出位置
- angular - 在我的情况下如何正确地发出 PUT 请求?
- python - 我如何解释列表元素中的重复
- javascript - Libsignal JavaScript 库
- python - 是否可以在 Python 中将 Thread 分配给一个函数,反之亦然?
- python - 如何计算大指数的数字