if (accessIndex != -1)
value = ((FieldAccess)access).get(object, accessIndex);
else
value = field.get(object);
Serializer serializer = this.serializer;
if (valueClass == null) {
// The concrete type of the field is unknown, write the class first.
if (value == null) {
kryo.writeClass(output, null);
return;
}
Registration registration = kryo.writeClass(output, value.getClass());
if (serializer == null) serializer = registration.getSerializer();
if (generics != null) serializer.setGenerics(kryo, generics);
kryo.writeObject(output, value, serializer);
} else {
// The concrete type of the field is known, always use the same serializer.
if (serializer == null) this.serializer = serializer = kryo.getSerializer(valueClass);
if (generics != null) serializer.setGenerics(kryo, generics);
if (canBeNull) {
kryo.writeObjectOrNull(output, value, serializer);
} else {
if (value == null) {
throw new KryoException("Field value is null but canBeNull is false: " + this + " ("