小编Saf*_*azi的帖子

JSON:使用与序列化名称 json 不同的反序列化名称

我有一个类User,我从 system1 收到 JSON(用于 User 类),我应该读取信息,验证然后转发到 system2,我无法触及这两个系统,问题是键的名称不同,我想区分收到的 JSON 的反序列化名称和序列化名称之间是:

{"userId":"user1","pwd":"123456","country":"US"}

"{"username":"user1","password":"123456","country":"US"}"

但发送的应该是这样的

我正在使用 Gson lib,这是我的代码:

用户类别:

class User implements Cloneable {

    @SerializedName("username")
    private String username ;
    
    @SerializedName("password")
    private String password ;
    
    @SerializedName("country")
    private String country ;

}
Run Code Online (Sandbox Code Playgroud)

TestJson 类

class TestJson {

    private static GsonBuilder gsonBuilder;
    private static Gson gson;

    public static Object fromJson(String json, Class clz) {
        gson = new Gson();
        return gson.fromJson(json, clz);
    }

    public static String toJson(Object obj) {
        gsonBuilder = new GsonBuilder();
        gson = …
Run Code Online (Sandbox Code Playgroud)

java json gson

4
推荐指数
2
解决办法
5213
查看次数

JSONObject不是字符串错误

    {
  "query": {
    "count": 1,
    "created": "2015-07-28T05:19:01Z",
    "lang": "en-US",
    "results": {
      "quote": {
        "symbol": "GITANJALI.NS",
        "Ask": null,
        "AverageDailyVolume": null,
        "Bid": null,
        "AskRealtime": null,
        "BidRealtime": null,
        "BookValue": null,
        "Change_PercentChange": null,
        "Change": null,
        "Commission": null,
        "Currency": null,
        "ChangeRealtime": null,
        "AfterHoursChangeRealtime": null,
        "DividendShare": null,
        "LastTradeDate": null,
        "TradeDate": null,
        "EarningsShare": "9.73",
        "ErrorIndicationreturnedforsymbolchangedinvalid": null,
        "EPSEstimateCurrentYear": null,
        "EPSEstimateNextYear": null,
        "EPSEstimateNextQuarter": null,
        "DaysLow": null,
        "DaysHigh": null,
        "YearLow": null,
        "YearHigh": null,
        "HoldingsGainPercent": null,
        "AnnualizedGain": null,
        "HoldingsGain": null,
        "HoldingsGainPercentRealtime": null,
        "HoldingsGainRealtime": null,
        "MoreInfo": null,
        "OrderBookRealtime": null,
        "MarketCapitalization": null,
        "MarketCapRealtime": …
Run Code Online (Sandbox Code Playgroud)

java json

3
推荐指数
2
解决办法
5125
查看次数

弹簧引导执行器不工作(未找到)版本 1.4.1

我从 spring 站点(https://spring.io/guides/gs/actuator-service)下载了这个示例,我遵循了相同的步骤,但是如果我调用这个 URL

显示http://localhost:9000/health spring启动错误页面

在此处输入图片说明

spring boot 版本是1.4.1,应该是 {"status":"UP"},有什么建议吗?

应用程序属性

server.port: 9000
management.port: 9001
management.address: 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

POM文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-actuator-service</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <properties>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
Run Code Online (Sandbox Code Playgroud)

日志:

在此处输入图片说明

spring spring-boot spring-boot-actuator

1
推荐指数
1
解决办法
5068
查看次数

标签 统计

java ×2

json ×2

gson ×1

spring ×1

spring-boot ×1

spring-boot-actuator ×1