I've already spent a lot of time trying to write custom serializer, to replace Int (TINYINT from mysql) to Boolean during serialization.
Using Gson I do it without problems, something like this (java):
public class BooleanSerializer implements JsonSerializer<Boolean>, JsonDeserializer<Boolean> {
@Override
public JsonElement serialize(Boolean arg0, Type arg1, JsonSerializationContext arg2) {
return new JsonPrimitive(arg0 ? 1 : 0);
}
@Override
public Boolean deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
return arg0.getAsInt() == 1;
}
}
GsonBuilder().registerTypeAdapter(Boolean.class, serializer)
maybe someone already solved a similar problem using kotlinx.serialization library?
Thank you.