ClassAliasIdResolver extends ClassNameIdResolver { public void addClassToId(final Class<?> clazz, final String id) { Assert.notNull(clazz, "Class cannot be null"); Assert.hasText(id, "Alias (id) cannot be null or contain only whitespaces"); if (classToId.containsKey(clazz)) { throw new IllegalArgumentException("Class " + clazz + " has already defined alias (id) " + classToId.get(clazz) + " cannot set another alias " + id); } if (idToClass.containsKey(id)) { throw new IllegalArgumentException("Alias (id) " + id + " is used by another class " + idToClass.get(id) + " and cannot be used by " + clazz); } classToId.put(clazz, id); idToClass.put(id, clazz); } ClassAliasIdResolver(final JavaType baseType, final TypeFactory typeFactory, final Map<String, Class<?>> idToClass,
            final Map<Class<?>, String> classToId); @Override String idFromValue(final Object value); @Override String idFromValueAndType(final Object value, final Class<?> type); void addClassToId(final Class<?> clazz, final String id);  }
@Test public void addClassToId() { resolver.addClassToId(ClassAliasIdResolverTest.class, "cairt"); String id = resolver.idFromValue(new ClassAliasIdResolverTest()); assertNotNull(id); assertEquals("cairt", id); id = resolver.idFromValue(new Object()); assertEquals(Object.class.getName(), id); }
@Test(expected = IllegalArgumentException.class) public void invalidAddClassToIdNullClass() { resolver.addClassToId(null, "id"); }
@Test(expected = IllegalArgumentException.class) public void invalidAddClassToIdMapNullAlias() { resolver.addClassToId(ClassAliasIdResolverTest.class, null); }
@Test(expected = IllegalArgumentException.class) public void invalidAddClassToIdMapEmptyAlias() { resolver.addClassToId(ClassAliasIdResolverTest.class, ""); }