#2909: Don't serialise as array for single element contents
This commit is contained in:
@@ -7,15 +7,11 @@ import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
@@ -25,13 +21,14 @@ import lombok.ToString;
|
||||
@ToString(of = "nbt")
|
||||
@EqualsAndHashCode(of = "nbt")
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public final class ItemTag
|
||||
{
|
||||
|
||||
@Getter
|
||||
private final String nbt;
|
||||
|
||||
/*
|
||||
TODO
|
||||
private BaseComponent name;
|
||||
@Singular("ench")
|
||||
private List<Enchantment> enchantments;
|
||||
@@ -39,6 +36,15 @@ public final class ItemTag
|
||||
private List<BaseComponent[]> lore;
|
||||
private Boolean unbreakable;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public static class Enchantment
|
||||
{
|
||||
|
||||
private final int level;
|
||||
private final int id;
|
||||
}
|
||||
*/
|
||||
|
||||
private ItemTag(String nbt)
|
||||
{
|
||||
this.nbt = nbt;
|
||||
@@ -49,28 +55,13 @@ public final class ItemTag
|
||||
return new ItemTag( nbt );
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public static class Enchantment
|
||||
{
|
||||
|
||||
private final int level;
|
||||
private final int id;
|
||||
}
|
||||
|
||||
public static class Serializer implements JsonSerializer<ItemTag>, JsonDeserializer<ItemTag>
|
||||
{
|
||||
|
||||
@Override
|
||||
public ItemTag deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
// Remove the enclosing string quotes.
|
||||
String eString = element.toString();
|
||||
if ( eString.length() >= 2 && eString.charAt( 0 ) == '\"' && eString.charAt( eString.length() - 1 ) == '\"' )
|
||||
{
|
||||
eString = eString.substring( 1, eString.length() - 1 );
|
||||
}
|
||||
|
||||
return ItemTag.ofNbt( eString );
|
||||
return ItemTag.ofNbt( element.getAsJsonPrimitive().getAsString() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -190,7 +190,8 @@ public class BaseComponentSerializer
|
||||
hoverEvent.add( "value", context.serialize( component.getHoverEvent().getContents().get( 0 ) ) );
|
||||
} else
|
||||
{
|
||||
hoverEvent.add( "contents", context.serialize( component.getHoverEvent().getContents() ) );
|
||||
hoverEvent.add( "contents", context.serialize( ( component.getHoverEvent().getContents().size() == 1 )
|
||||
? component.getHoverEvent().getContents().get( 0 ) : component.getHoverEvent().getContents() ) );
|
||||
}
|
||||
object.add( "hoverEvent", hoverEvent );
|
||||
}
|
||||
|
Reference in New Issue
Block a user