Skip to content

Commit

Permalink
Solve "StackOverflowException" on BackgroundTypeAdapter when the obje…
Browse files Browse the repository at this point in the history
…ct is of an incompatible type
  • Loading branch information
mircoianese committed Aug 19, 2024
1 parent a2a5b3d commit 56ef37a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.pengrad.telegrambot.model.chatbackground;

import java.util.Objects;

public class BackgroundTypeUnknown extends BackgroundType {

public static final String TYPE = "unknown";

public BackgroundTypeUnknown() {
super(TYPE);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return true;
}

@Override
public String toString() {
return "BackgroundTypeUnknown{" +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.pengrad.telegrambot.utility.gson;

import com.google.gson.*;
import com.pengrad.telegrambot.model.chatbackground.BackgroundType;
import com.pengrad.telegrambot.model.chatbackground.BackgroundTypeChatTheme;
import com.pengrad.telegrambot.model.chatbackground.BackgroundTypeFill;
import com.pengrad.telegrambot.model.chatbackground.BackgroundTypePattern;
import com.pengrad.telegrambot.model.chatbackground.BackgroundTypeWallpaper;
import com.pengrad.telegrambot.model.chatbackground.*;

import java.lang.reflect.Type;

Expand All @@ -26,6 +22,6 @@ public BackgroundType deserialize(JsonElement element, Type type, JsonDeserializ
return context.deserialize(object, BackgroundTypeChatTheme.class);
}

return context.deserialize(object, BackgroundType.class);
return new BackgroundTypeUnknown();
}
}

0 comments on commit 56ef37a

Please sign in to comment.