sekassel / stp-24-server-tracker

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

Server has game with settingtype array #5

Closed ElenaSotoSobrino closed 3 months ago

ElenaSotoSobrino commented 3 months ago

Describe the bug In the Game model of the server is an attribute "settings" which should be an integer. But somehow another user of this server created a game with "settings" as an empty array. Now if we are loading all Games, there will be an error because an array cannot be converted to an integer.

The Game has following attributes: "_id": "664df2647d4305b118a4733d", "name": "default", "owner": "662b83dea51a788b23a74d4b", "started": false, "speed": 1, "period": 0, "settings": [], "createdAt": "2024-05-22T13:25:56.541Z", "updatedAt": "2024-05-22T13:25:56.541Z", "members": 1

Expected behavior Please delete this game and try to fix this, so user cannot create a game with setting with typ array

PygmalesDev commented 3 months ago

There are more than one instance of a such buggy game: изображение id: 664e159f7d4305b118a4f48a изображение id: 664dfc707d4305b118a4a4e0 изображение id: 664df2647d4305b118a4733d

Clashsoft commented 3 months ago

I have deleted some but someone keeps creating more. I have changed the string user password to see who is the culprit.

NoCodeNoBlunder commented 3 months ago

I have found some configuration for the Jackson Deserializer we are using that allows to fix this issue to some extent. The Sollution is enabling ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT see the code below.

@Module
public class MainModule {
    @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(SerializationFeature.INDENT_OUTPUT)
            // This Line can help.
            .enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
    }
}