2

The response from postman is

{
    "relation": [
        {
            "trans_id": 1,
            "data": {
                "PLC_id": 1,
                "temp_id": 1,
                "sla_id": 1
            }
        }
    ]
}

The way to get a response is

Mono<ClientResponse> response = WebClient.builder()
                .baseUrl(baseUrl)
                .build()
                .post()
                .uri("/sync")
                .contentType(MediaType.APPLICATION_JSON_UTF8)
                .accept(MediaType.APPLICATION_JSON_UTF8)
                .syncBody("{\"id\":1}")
                .exchange();
Info result = response.block().bodyToMono(Info.class).block();

But the result is like

Info(relation=[Trans(trans_id=1, data=PLC(PLC_id=null, temp_id=1, sla_id=1))])

The POJO PLC class is

import lombok.Data;

@Data
public class PLC {
    private Integer PLC_id;
    private Integer temp_id;
    private Integer sla_id;
}

The spelling is checked several times, they are identical.
So why the PLC_id is null? What could be the problem?

My problem is different from Part of JSON response from server is returning null: Android It's missing a key, while I have the key but with null value.

Shihe Zhang
  • 2,641
  • 5
  • 36
  • 57

1 Answers1

2

Enlighten by my coworker. Change the json response PLC_id to lowercase and it works fine.
So I searched something related to json uppercase, find the following question is most related to my situation.
Spring REST consuming JSON uppercase vs lowercase

so one way is to change the response body. Another is to

You can use @JsonProperty annotation to override the variable name.

@JsonProperty("phone")   
public String PHONE;

There are also other related questions, mainly about case problem.

Is there any way to create JSON object with keys as upper case?
How to convert all keys in JSON response to uppercase? (JAVA)
Jackson - Java bean to JSON string : uppercase variable converted into lowercase in JSON
Jackson - converting java object to json - Need all key keys to upper case
Is there any way to create JSON object with keys as upper case?

Shihe Zhang
  • 2,641
  • 5
  • 36
  • 57