diff --git a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java index 5a5ba50..801e2d2 100644 --- a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java +++ b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java @@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.skcraft.launcher.model.minecraft.mapper.MinecraftArgumentsDeserializer; +import com.skcraft.launcher.model.minecraft.mapper.MinecraftArgumentsSerializer; import lombok.Data; import java.util.List; @@ -14,11 +16,13 @@ import java.util.List; public class MinecraftArguments { @JsonProperty("game") @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) + @JsonSerialize(contentUsing = MinecraftArgumentsSerializer.class) @JsonDeserialize(contentUsing = MinecraftArgumentsDeserializer.class) private List gameArguments; @JsonProperty("jvm") @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) + @JsonSerialize(contentUsing = MinecraftArgumentsSerializer.class) @JsonDeserialize(contentUsing = MinecraftArgumentsDeserializer.class) private List jvmArguments; } diff --git a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/mapper/MinecraftArgumentsSerializer.java b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/mapper/MinecraftArgumentsSerializer.java new file mode 100644 index 0000000..7b579a2 --- /dev/null +++ b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/mapper/MinecraftArgumentsSerializer.java @@ -0,0 +1,24 @@ +package com.skcraft.launcher.model.minecraft.mapper; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.skcraft.launcher.model.minecraft.GameArgument; + +import java.io.IOException; + +public class MinecraftArgumentsSerializer extends StdSerializer { + protected MinecraftArgumentsSerializer() { + super(GameArgument.class); + } + + @Override + public void serialize(GameArgument value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { + if (value.getValues().size() == 1 && (value.getRules() == null || value.getRules().size() == 0)) { + jgen.writeString(value.getValues().get(0)); + } else { + provider.defaultSerializeValue(value, jgen); + } + } +}