mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-30 14:39:56 +08:00
parent
db59dcea65
commit
4d7af2e68b
@ -30,7 +30,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
@JsonAdapter(Argument.Serializer.class)
|
||||
@JsonAdapter(Argument.Deserializer.class)
|
||||
@Immutable
|
||||
public interface Argument extends Cloneable {
|
||||
|
||||
@ -43,7 +43,7 @@ public interface Argument extends Cloneable {
|
||||
*/
|
||||
List<String> toString(Map<String, String> keys, Map<String, Boolean> features);
|
||||
|
||||
class Serializer implements JsonDeserializer<Argument>, JsonSerializer<Argument> {
|
||||
class Deserializer implements JsonDeserializer<Argument> {
|
||||
@Override
|
||||
public Argument deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive())
|
||||
@ -51,16 +51,5 @@ public interface Argument extends Cloneable {
|
||||
else
|
||||
return context.deserialize(json, RuledArgument.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Argument src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src instanceof StringArgument)
|
||||
return new JsonPrimitive(((StringArgument) src).getArgument());
|
||||
else if (src instanceof RuledArgument)
|
||||
return context.serialize(src, RuledArgument.class);
|
||||
else
|
||||
throw new AssertionError("Unrecognized argument type: " + src);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,13 @@ package org.jackhuang.hmcl.game;
|
||||
|
||||
import org.jackhuang.hmcl.util.Immutable;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -29,6 +36,7 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
@JsonAdapter(StringArgument.Serializer.class)
|
||||
@Immutable
|
||||
public final class StringArgument implements Argument {
|
||||
|
||||
@ -58,4 +66,11 @@ public final class StringArgument implements Argument {
|
||||
public String toString() {
|
||||
return argument;
|
||||
}
|
||||
|
||||
public class Serializer implements JsonSerializer<StringArgument> {
|
||||
@Override
|
||||
public JsonElement serialize(StringArgument src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getArgument());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user