Fix adapters order

This commit is contained in:
Andrea Cavalli 2021-06-08 19:42:20 +02:00
parent 47c505d755
commit 74593538dc

View File

@ -49,12 +49,14 @@ public abstract class MoshiPolymorphic<OBJ> {
var concreteClasses = getConcreteClasses();
var extraAdapters = getExtraAdapters();
extraAdapters.forEach(abstractMoshiBuilder::addLast);
for (Class<?> declaredClass : abstractClasses) {
var name = fixType(declaredClass.getSimpleName());
JsonAdapter<OBJ> adapter = new PolymorphicAdapter<>(name);
abstractClassesSerializers.put(declaredClass, adapter);
customAdapters.put(name, adapter);
abstractMoshiBuilder.add(declaredClass, adapter);
abstractMoshiBuilder.addLast(declaredClass, adapter);
}
for (Class<?> declaredClass : concreteClasses) {
@ -62,12 +64,10 @@ public abstract class MoshiPolymorphic<OBJ> {
JsonAdapter<OBJ> adapter = new NormalValueAdapter<>(name, declaredClass);
concreteClassesSerializers.put(declaredClass, adapter);
customAdapters.put(name, adapter);
abstractMoshiBuilder.add(declaredClass, adapter);
abstractMoshiBuilder.addLast(declaredClass, adapter);
}
extraAdapters.forEach(abstractMoshiBuilder::add);
abstractMoshiBuilder.add(new RecordsJsonAdapterFactory());
abstractMoshiBuilder.addLast(new RecordsJsonAdapterFactory());
abstractMoshi = abstractMoshiBuilder.build();
}