0

I have a GET endpoint in my application supposed to return :

{
  "gameId": "41a483c4-6220-424a-a931-d9114a4f6748",
  "pits": [
    {
      "id": 1,
      "stones": 6
    },
    {
      "id": 2,
      "stones": 6
    },
    {
      "id": 3,
      "stones": 6
    },
    {
      "id": 4,
      "stones": 6
    },
    {
      "id": 5,
      "stones": 6
    },
    {
      "id": 6,
      "stones": 6
    },
    {
      "id": 7,
      "stones": 0
    },
    {
      "id": 8,
      "stones": 6
    },
    {
      "id": 9,
      "stones": 6
    },
    {
      "id": 10,
      "stones": 6
    },
    {
      "id": 11,
      "stones": 6
    },
    {
      "id": 12,
      "stones": 6
    },
    {
      "id": 13,
      "stones": 6
    },
    {
      "id": 14,
      "stones": 0
    }
  ],
  "playerTurn": null,
  "currentPitIndex": 0
}

but instead it returns:

{
    "id": "25f09303-b797-418f-a7e7-db0e5fa8631b",
    "pits": [
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 0,
            "empty": true
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 6,
            "empty": false
        },
        {
            "stones": 0,
            "empty": true
        }
    ],
    "playerTurn": null,
    "currentPitIndex": null
}

I am wondering what is "empty"?! and where is "id"!

would be much appreciated for any suggestion and help. thank you

1
  • Please provide the method in the Controller as well as the object it returns. Rob's answer should point you in the right direction though. Commented Mar 12, 2022 at 11:41

1 Answer 1

1

Does your class have a method called isEmpty()? Because most JSON marshalling frameworks add JSON properties for any method with 0 arguments that starts with get, or returns a boolean and starts with is. For the same reason id is probably missing - I'm guessing there is no getter for it. The top level gameId is probably called id because you have a getId() method, not a getGameId() method.

For most frameworks you can tweak this with annotations. For instance, with Jackon you can use @JsonIgnore to indicate a method should not be represented as a JSON property, and @JsonProperty can be used to a) add a custom name, or b) allow a field to be included as well. For other frameworks you should check their documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Rob Spoor, edit:( I made a spelling mistake in my question gameId is actually id). I am not using isEmpty method
I found isEmpty() metod. checking that the stones value is 0 or not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.