#3662: Add deprecation warning to ComponentSerializer.toString(Object)

It taking all objects is error-prone, deprecate it and create overloads
for used acceptable types.
This commit is contained in:
Janmm14 2024-08-25 09:27:40 +10:00 committed by md_5
parent d32eedd333
commit 79f85a2ce2
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -20,6 +20,7 @@ import net.md_5.bungee.api.chat.ScoreComponent;
import net.md_5.bungee.api.chat.SelectorComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.TranslatableComponent;
import net.md_5.bungee.api.chat.hover.content.Content;
import net.md_5.bungee.api.chat.hover.content.Entity;
import net.md_5.bungee.api.chat.hover.content.EntitySerializer;
import net.md_5.bungee.api.chat.hover.content.Item;
@ -158,11 +159,28 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
return gson.toJsonTree( style );
}
/**
* @param object the object to serialize
* @return the JSON string representation of the object
* @deprecated Error-prone, be careful which object you input here
*/
@Deprecated
public static String toString(Object object)
{
return gson.toJson( object );
}
/**
* @param content the content to serialize
* @return the JSON string representation of the object
* @deprecated for legacy internal use only
*/
@Deprecated
public static String toString(Content content)
{
return gson.toJson( content );
}
public static String toString(BaseComponent component)
{
return gson.toJson( component );