package com.fasterxml.jackson.databind.jsontype.impl;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;

public abstract class TypeSerializerBase extends TypeSerializer
{
    protected final TypeIdResolver _idResolver;

    protected final BeanProperty _property;
    
    protected TypeSerializerBase(TypeIdResolver idRes, BeanProperty property)
    {
        _idResolver = idRes;
        _property = property;
    }

    @Override
    public abstract JsonTypeInfo.As getTypeInclusion();

    @Override
    public String getPropertyName() { return null; }
    
    @Override
    public TypeIdResolver getTypeIdResolver() { return _idResolver; }

    /*
    /**********************************************************
    /* Helper methods for subclasses
    /**********************************************************
     */

    protected String idFromValue(Object value) {
        return _idResolver.idFromValue(value);
    }

    protected String idFromValueAndType(Object value, Class<?> type) {
        return _idResolver.idFromValueAndType(value, type);
    }
}

@@ -1053,38 +1053,43 @@
 alue) %7B%0A        
-return
+String id =
  _idResolver.idF
@@ -1101,24 +1101,322 @@
 lue(value);%0A
+        if (id == null) %7B%0A            String typeDesc = (value == null) ? %22NULL%22 : value.getClass().getName();%0A            throw new IllegalArgumentException(%22Can not resolve type id for %22%0A                    +typeDesc+%22 (using %22+_idResolver.getClass().getName()+%22)%22);%0A        %7D%0A        return id;%0A
     %7D%0A%0A    p
@@ -1489,22 +1489,27 @@
         
-return
+String id =
  _idReso
@@ -1542,20 +1542,318 @@
 lue, type);%0A
+        if (id == null) %7B%0A            String typeDesc = (value == null) ? %22NULL%22 : value.getClass().getName();%0A            throw new IllegalArgumentException(%22Can not resolve type id for %22%0A                    +typeDesc+%22 (using %22+_idResolver.getClass().getName()+%22)%22);%0A        %7D%0A        return id;%0A
     %7D%0A%7D%0A

Add more consistency checks for type id generation