forked from Cookies_Github_mirror/AquaDX
[chusan]Attempting to ensure compatibility with all known versions of Chusan, both before and after SunPlus
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.chusan.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanStringIntDeserializer extends JsonDeserializer<Boolean> {
|
||||
@Override
|
||||
public Boolean deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
return switch (p.getCurrentToken()) {
|
||||
case VALUE_STRING -> p.getText().trim().equals("1") || p.getText().trim().equalsIgnoreCase("true");
|
||||
case VALUE_NUMBER_INT -> p.getIntValue() == 1;
|
||||
case VALUE_TRUE -> true;
|
||||
case VALUE_FALSE -> false;
|
||||
default -> throw new UnsupportedOperationException("Cannot deserialize to boolean field");
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package icu.samnyan.aqua.sega.chusan.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BooleanToIntegerDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
return switch (p.getCurrentToken()) {
|
||||
case VALUE_STRING -> {
|
||||
String value = p.getValueAsString();
|
||||
if (value.toLowerCase(Locale.ROOT).equals("true")) {
|
||||
yield 1;
|
||||
} else if (value.toLowerCase(Locale.ROOT).equals("false")) {
|
||||
yield 0;
|
||||
} else {
|
||||
try {
|
||||
yield Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new UnsupportedOperationException("Cannot deserialize to integer field");
|
||||
}
|
||||
}
|
||||
}
|
||||
case VALUE_NUMBER_INT -> p.getIntValue();
|
||||
case VALUE_TRUE -> 1;
|
||||
case VALUE_FALSE -> 0;
|
||||
default -> throw new UnsupportedOperationException("Cannot deserialize to integer field");
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user