首页 > 解决方案 > 泽西 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'

然而仍然得到同样的错误。我不确定接下来我可以尝试什么....

标签: javajersey

解决方案


推荐阅读