我正在开发一个应用程序来触发java中的AWS lambda。要触发 lambda,我需要在请求中发送 json 对象。我无法使用 Gson

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

我正在开发一个应用程序来触发java中的AWS lambda。要触发 lambda,我需要在请求中发送 json 对象。我无法使用 Gson。我添加了以下 Maven 依赖项。

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>


    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.13</version>
    </dependency>


    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.16.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.10.1</version>
    </dependency>

请帮我解决问题。

我已经尝试了所有可能的方法,但无法找出问题所在。

java appium
1个回答
0
投票

我不知道你想做什么。

只需在 Gson 的 pom.xml 中添加此依赖项即可:

<dependencies>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.10.1</version>
    </dependency>
</dependencies>

演示示例代码:

import com.google.gson.Gson;

class Sample {
    private String field;

    public Sample(String field) {
        this.field = field;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }
}

public class Test {
    public static void main(String[] args) {
        Sample s = new Sample("abc");
        String abc = new Gson().toJson(s);
        System.out.println(abc);
    }
}

输出:

{"field":"abc"}

希望这有帮助。这是一个例子。相应地更改代码。

© www.soinside.com 2019 - 2024. All rights reserved.