Update moshi
This commit is contained in:
parent
d752af85d7
commit
d8cdb45cb0
@ -12,6 +12,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiFunction;
|
||||
@ -45,6 +46,7 @@ public abstract class MoshiPolymorphic<OBJ> {
|
||||
var abstractMoshiBuilder = new Moshi.Builder();
|
||||
var abstractClasses = getAbstractClasses();
|
||||
var concreteClasses = getConcreteClasses();
|
||||
var extraAdapters = getExtraAdapters();
|
||||
|
||||
for (Class<?> declaredClass : abstractClasses) {
|
||||
var name = fixType(declaredClass.getSimpleName());
|
||||
@ -55,7 +57,6 @@ public abstract class MoshiPolymorphic<OBJ> {
|
||||
}
|
||||
|
||||
for (Class<?> declaredClass : concreteClasses) {
|
||||
var modifiers = declaredClass.getModifiers();
|
||||
var name = fixType(declaredClass.getSimpleName());
|
||||
JsonAdapter<OBJ> adapter = new NormalValueAdapter<>(name, declaredClass);
|
||||
concreteClassesSerializers.put(declaredClass, adapter);
|
||||
@ -63,6 +64,8 @@ public abstract class MoshiPolymorphic<OBJ> {
|
||||
abstractMoshiBuilder.add(declaredClass, adapter);
|
||||
}
|
||||
|
||||
extraAdapters.forEach(abstractMoshiBuilder::add);
|
||||
|
||||
abstractMoshi = abstractMoshiBuilder.build();
|
||||
}
|
||||
}
|
||||
@ -71,6 +74,10 @@ public abstract class MoshiPolymorphic<OBJ> {
|
||||
|
||||
protected abstract Set<Class<OBJ>> getConcreteClasses();
|
||||
|
||||
protected Map<Class<?>, JsonAdapter<?>> getExtraAdapters() {
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
protected abstract boolean shouldIgnoreField(String fieldName);
|
||||
|
||||
public Moshi.Builder registerAdapters(Moshi.Builder moshiBuilder) {
|
||||
|
Loading…
Reference in New Issue
Block a user