Skip to content

Commit

Permalink
#3662: Add deprecation warning to ComponentSerializer.toString(Object)
Browse files Browse the repository at this point in the history
It taking all objects is error-prone, deprecate it and create overloads
for used acceptable types.
  • Loading branch information
Janmm14 authored and md-5 committed Aug 24, 2024
1 parent d32eedd commit 79f85a2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions chat/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -158,11 +159,28 @@ public static JsonElement toJson(ComponentStyle style)
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 );
Expand Down

0 comments on commit 79f85a2

Please sign in to comment.