sekassel / stp-24-server-tracker

Issue Tracker and Feature Requests for the STP 2024 Server.
0 stars 0 forks source link

Can not set Empire to null via code (when game member already has an empire) #6

Closed AshkanKiafard closed 3 months ago

AshkanKiafard commented 3 months ago

Describe the bug We have a member of a game with an (non null) empire and when we try to patch this member and set its empire to null, we send a updateMemeberDTO containing a null empire but the server doesn't overwrite the current empire and the response with server contains the old non null empire.

To Reproduce Steps to reproduce the behavior:

  1. Have a game member in lobby with already existing empire.
  2. Call a patch return this.gameMembersApiService.patchMember(gameID, userID, new UpdateMemberDto(ready, null)); GameMemberApiService:
    @PATCH("games/{game}/members/{user}")
    Observable<MemberDto> patchMember(@Path("game") String gameID, @Path("user") String userID,
                                      @Body UpdateMemberDto updateMemberDto);
  3. Check the response of the server. It contains the old non null empire.

Expected behavior Server should give a response back, that has empire as null.

Additional context We want to set the players without empires as spectators but because of this problem, we can't.

AshkanKiafard commented 3 months ago

But when we try to set empire to null via Swagger, it works.

AshkanKiafard commented 3 months ago

We found the cause.

In MainModule you should comment this line .setSerializationInclusion(JsonInclude.Include.NON_ABSENT)

@Provides
    @Singleton
    ObjectMapper mapper() {
        return new ObjectMapper()
            .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            // .setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
            .enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
    }