44
55import com .cleanroommc .modularui .api .drawable .IDrawable ;
66import com .cleanroommc .modularui .api .drawable .IKey ;
7- import com .google .gson .JsonArray ;
87import com .google .gson .JsonDeserializationContext ;
98import com .google .gson .JsonElement ;
109import com .google .gson .JsonObject ;
1110import com .google .gson .JsonParseException ;
1211import com .google .gson .JsonSerializationContext ;
1312
14- import java .util .ArrayList ;
15- import java .util .List ;
13+ import java .util .Arrays ;
1614
1715public class DrawableSerializer implements JsonHandler <IDrawable > {
1816
@@ -24,11 +22,8 @@ public IDrawable deserialize(JsonElement json, JsonDeserializationContext contex
2422 if (parsed .has ("key" ) && parsed .has ("tooltip" )) {
2523 IKey key = context .deserialize (parsed .get ("key" ), IKey .class );
2624
27- List <IDrawable > list = new ArrayList <>();
28- for (JsonElement jsonElement : parsed .getAsJsonArray ("tooltip" )) {
29- list .add (context .deserialize (jsonElement , IDrawable .class ));
30- }
31- return HoverableKey .of (key ).addLines (list );
25+ IDrawable [] list = deserializeArray (parsed .getAsJsonArray ("tooltip" ), context , IDrawable []::new );
26+ return HoverableKey .of (key ).addLines (Arrays .asList (list ));
3227 } else {
3328 return context .deserialize (parsed , IKey .class );
3429 }
@@ -40,12 +35,7 @@ public JsonElement serialize(IDrawable src, JsonSerializationContext context) {
4035 JsonObject object = new JsonObject ();
4136 if (src instanceof HoverableKey hoverable ) {
4237 object .add ("key" , context .serialize (hoverable .getKey (), IKey .class ));
43- JsonArray array = new JsonArray ();
44- for (IDrawable tooltipLine : hoverable .getTooltipLines ()) {
45- array .add (context .serialize (tooltipLine , IDrawable .class ));
46- }
47- object .add ("tooltip" , array );
48- return object ;
38+ object .add ("tooltip" , serializeArray (hoverable .getTooltipLines (), context ));
4939 }
5040 return object ;
5141 }
0 commit comments