protected boolean hasDefault(JsonTypeInfo typeInfo) { return !typeInfo.defaultImpl().equals(JsonTypeInfo.class); } }
protected void testRoot() { // while boundaries are compiler-checked, let's still verify superclass, as generics in Java are easy to bypass assertTrue("Invalid root type: " + expectedRoot, PolymorphicConfiguration.class.isAssignableFrom(expectedRoot)); JsonTypeInfo typeInfo = expectedRoot.getAnnotation(JsonTypeInfo.class); // TODO: test "property" and "use" values of the annotation assertNotNull("Root is not annotated with @JsonTypeInfo", typeInfo); if (expectedDefault != null) { assertTrue("Default type is not specified on root. Expected: " + expectedDefault.getName(), hasDefault(typeInfo)); assertEquals("Expected and actual default types are not the same", expectedDefault, typeInfo.defaultImpl()); } else { assertFalse("Expected no default type, but @JsonTypeInfo sets it to " + typeInfo.defaultImpl().getName() + ".", hasDefault(typeInfo)); } if (isConcrete(expectedRoot)) { JsonTypeName typeName = expectedRoot.getAnnotation(JsonTypeName.class); assertNotNull("Concrete root configuration type must be annotated with @JsonTypeName: " + expectedRoot.getName(), typeName); } }
Class<?> defaultImpl = info.defaultImpl();
public static Value from(JsonTypeInfo src) { if (src == null) { return null; } return construct(src.use(), src.include(), src.property(), src.defaultImpl(), src.visible()); }
private void saveType(String path, T object, KeyValueStorage storage) { Class<?> clazz = object.getClass(); String name = PROP_TYPE; String value = clazz.getName(); JsonTypeInfo typeInfo = AnnotationUtils.findAnnotation(clazz, JsonTypeInfo.class); if (typeInfo != null && !clazz.equals(typeInfo.defaultImpl())) { JsonTypeInfo.As include = typeInfo.include(); if(include != JsonTypeInfo.As.PROPERTY && include != JsonTypeInfo.As.EXTERNAL_PROPERTY /* it for capability with jackson oddities */) { throw new IllegalArgumentException("On " + clazz + " mapping support only " + JsonTypeInfo.As.PROPERTY + " but find: " + include); } name = getPropertyName(typeInfo); value = getJsonType(clazz, typeInfo); } storage.set(KvUtils.join(path, name), value); }
if (typeInfo != null) { subTypes = (JsonSubTypes) ObjectHelper.getClassAnnotation(implClass, JsonSubTypes.class); defaultImplClass = typeInfo.defaultImpl(); JsonTypeInfo.Id use = typeInfo.use(); JsonTypeInfo.As include = typeInfo.include();
Class<?> defaultImpl = info.defaultImpl();
Class<?> defaultImpl = info.defaultImpl();
Class<?> defaultImpl = info.defaultImpl();
Class<?> defaultImpl = info.defaultImpl();
Class<?> defaultImpl = info.defaultImpl(); if (defaultImpl != JsonTypeInfo.None.class) { b = b.defaultImpl(defaultImpl);
Class<?> defaultImpl = info.defaultImpl(); if (defaultImpl != JsonTypeInfo.None.class) { b = b.defaultImpl(defaultImpl);