mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-27 12:46:22 +01:00
Add custom serializer for game arguments for more concise version JSON
This commit is contained in:
parent
c25e672869
commit
5f0b44acd3
@ -4,9 +4,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.skcraft.launcher.model.minecraft.mapper.ArgumentValueDeserializer;
|
||||
import com.skcraft.launcher.model.minecraft.mapper.ArgumentValueSerializer;
|
||||
import com.skcraft.launcher.util.Environment;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -19,6 +21,7 @@ import java.util.List;
|
||||
public class GameArgument {
|
||||
@JsonProperty("value")
|
||||
@JsonDeserialize(using = ArgumentValueDeserializer.class)
|
||||
@JsonSerialize(using = ArgumentValueSerializer.class)
|
||||
private List<String> values;
|
||||
private List<Rule> rules;
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
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.fasterxml.jackson.databind.type.TypeFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class ArgumentValueSerializer extends StdSerializer<List<String>> {
|
||||
protected ArgumentValueSerializer() {
|
||||
super(TypeFactory.defaultInstance().constructCollectionType(List.class, String.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(List<String> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
|
||||
if (value.size() == 1) {
|
||||
jgen.writeString(value.get(0));
|
||||
} else {
|
||||
provider.defaultSerializeValue(value, jgen);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user