Skip to content

Commit

Permalink
deserialize plain arrays as list ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbie5 committed Dec 23, 2024
1 parent d3c3fe6 commit 9c35df0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public static EmiIngredient deserialize(JsonElement element) {
}
}
type = json.get("type").getAsString();
} else if (element.isJsonArray()) {
type = "list";
} else {
String[] split = element.getAsString().split(":");
type = split[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ public String getType() {

@Override
public EmiIngredient deserialize(JsonElement element) {
if (!element.isJsonObject()) {
JsonArray ingredientsArray;
long amount;
float chance;
if (element.isJsonObject()) {
JsonObject json = element.getAsJsonObject();
amount = JsonHelper.getLong(json, "amount", 1);
chance = JsonHelper.getFloat(json, "chance", 1);
ingredientsArray = JsonHelper.getArray(json, "ingredients");
} else if (element.isJsonArray()) {
ingredientsArray = element.getAsJsonArray();
amount = 1;
chance = 1;
} else {
return EmiStack.EMPTY;
}
JsonObject json = element.getAsJsonObject();
long amount = JsonHelper.getLong(json, "amount", 1);
float chance = JsonHelper.getFloat(json, "chance", 1);
JsonArray ingredientsArray = JsonHelper.getArray(json, "ingredients");
List<EmiIngredient> ingredients = new ArrayList<>();
for (JsonElement ingredientElement : ingredientsArray) {
ingredients.add(EmiIngredientSerializers.deserialize(ingredientElement));
Expand Down

0 comments on commit 9c35df0

Please sign in to comment.