mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 15:26:27 -04:00
parent
db59dcea65
commit
4d7af2e68b
@ -30,7 +30,7 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
@JsonAdapter(Argument.Serializer.class)
|
@JsonAdapter(Argument.Deserializer.class)
|
||||||
@Immutable
|
@Immutable
|
||||||
public interface Argument extends Cloneable {
|
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);
|
List<String> toString(Map<String, String> keys, Map<String, Boolean> features);
|
||||||
|
|
||||||
class Serializer implements JsonDeserializer<Argument>, JsonSerializer<Argument> {
|
class Deserializer implements JsonDeserializer<Argument> {
|
||||||
@Override
|
@Override
|
||||||
public Argument deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public Argument deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
if (json.isJsonPrimitive())
|
if (json.isJsonPrimitive())
|
||||||
@ -51,16 +51,5 @@ public interface Argument extends Cloneable {
|
|||||||
else
|
else
|
||||||
return context.deserialize(json, RuledArgument.class);
|
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 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.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -29,6 +36,7 @@ import java.util.regex.Pattern;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
|
@JsonAdapter(StringArgument.Serializer.class)
|
||||||
@Immutable
|
@Immutable
|
||||||
public final class StringArgument implements Argument {
|
public final class StringArgument implements Argument {
|
||||||
|
|
||||||
@ -58,4 +66,11 @@ public final class StringArgument implements Argument {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return argument;
|
return argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Serializer implements JsonSerializer<StringArgument> {
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(StringArgument src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
return new JsonPrimitive(src.getArgument());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user