public static ObjectType dictionaryOf(TypeBuilder<?> valueTypeBuilder) { return TYPE_BUILDER.objectType().openWith(valueTypeBuilder) .with(new ClassInformationAnnotation(Map.class)) .build(); }
} else { nullSafeType = new BaseTypeBuilder(JAVA).objectType() .with(new TypeIdAnnotation(nullSafe.defaultImplementingType().getName())) .build();
@Test public void getDataTypeFromMap() { Class<Date> dateClass = Date.class; Class<Map> mapClass = Map.class; ObjectTypeBuilder objectTypeBuilder = BaseTypeBuilder .create(JAVA) .objectType() .with(new ClassInformationAnnotation(Map.class)); objectTypeBuilder.openWith().objectType().id(dateClass.getName()); MapDataType dataType = (MapDataType) toDataType(objectTypeBuilder.build()); assertThat(dataType.getType(), is(equalTo(mapClass))); assertThat(dataType.getKeyDataType().getType(), is(equalTo(String.class))); assertThat(dataType.getValueDataType().getType(), is(equalTo(dateClass))); }
public ObjectTypeBuilder label(String label) { return with(new LabelAnnotation(label)); }
public ObjectTypeBuilder id(String typeIdentifier) { return with(new TypeIdAnnotation(typeIdentifier)); }
public ObjectTypeBuilder description(String lang, String content) { return with(new DescriptionAnnotation(content, lang)); }
public ObjectTypeBuilder description(String content) { return with(new DescriptionAnnotation(content)); }
@Test public void declareStaticAndDynamicTypesInSource() { List<SourceDeclaration> messageSources = declaration.getConfigurations().get(0).getMessageSources(); SourceDeclaration sourceDynamicAttributes = getDeclaration(messageSources, "MetadataSource"); assertOutputType(sourceDynamicAttributes.getOutput(), TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))) .openWith(TYPE_LOADER.load(Object.class)).build(), true); assertOutputType(sourceDynamicAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false); assertParameterType(getDeclaration(sourceDynamicAttributes.getAllParameters(), "type"), toMetadataType(String.class)); messageSources = declaration.getMessageSources(); SourceDeclaration sourceStaticAttributes = getDeclaration(messageSources, "MetadataSourceWithMultilevel"); assertOutputType(sourceStaticAttributes.getOutput(), TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))) .openWith(TYPE_LOADER.load(Object.class)).build(), true); assertOutputType(sourceStaticAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false); List<ParameterDeclaration> locationKey = sourceStaticAttributes.getAllParameters(); assertParameterType(getDeclaration(locationKey, "continent"), toMetadataType(String.class)); assertParameterType(getDeclaration(locationKey, "country"), toMetadataType(String.class)); assertParameterType(getDeclaration(locationKey, "city"), toMetadataType(String.class)); }
.id(InputStream.class.getName()) .with(new TypedValueTypeAnnotation())) .with(new TypeIdAnnotation(Map.class.getName())) .build(); .ofType(TYPE_BUILDER.objectType() .openWith(loader.load(String.class)) .with(new TypeIdAnnotation(Map.class.getName())) .build()) .withDsl(ParameterDslConfiguration.getDefaultInstance())
@Override public TypeBuilder<?> handleClass(Class<?> clazz, List<Type> genericTypes, TypeHandlerManager typeHandlerManager, ParsingContext context, BaseTypeBuilder typeBuilder) { final ObjectTypeBuilder objectTypeBuilder = typeBuilder.objectType(); if (genericTypes.isEmpty()) { //If no generic look in the inherited interfaces implementedInterfacesGenericsOrDefault(clazz, typeHandlerManager, context, objectTypeBuilder); } else if (genericTypes.size() != 2) { throw new IllegalArgumentException(String.format("Exactly 2 generics were expected but %d were provided instead", genericTypes.size())); } else { openWith(typeHandlerManager, context, objectTypeBuilder, genericTypes.get(1)); } objectTypeBuilder.with(new ClassInformationAnnotation(clazz, genericTypes)); return objectTypeBuilder; }
assertParameter(operation.getAllParameters(), "healthByYear", "", TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, HealthStatus.class))) .openWith(TYPE_LOADER.load(HealthStatus.class)) .build(),
TYPE_BUILDER.objectType() .openWith(TYPE_BUILDER.numberType().integer().with(new ClassInformationAnnotation(Long.class))) .with(new ClassInformationAnnotation(Map.class, asList(String.class, Long.class))) .build(), false, SUPPORTED, null); TYPE_BUILDER.objectType() .openWith((objectTypeBuilder(KnockeableDoor.class)).build()) .with(new ClassInformationAnnotation(Map.class, asList(String.class, KnockeableDoor.class))) .build(), false, SUPPORTED, null); TYPE_BUILDER.objectType() .openWith(objectTypeBuilder(Ricin.class)) .with(new ClassInformationAnnotation(Map.class, asList(String.class, Ricin.class))) .build(), false, SUPPORTED, null); assertParameter(parameters, "deathsBySeasons", "", TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, List.class))) .openWith(TYPE_BUILDER.arrayType() .of(TYPE_BUILDER.stringType())) assertParameter(parameters, "weaponValueMap", "", TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, Weapon.class))) .openWith(WEAPON_TYPE) .build(),
@Override public TypeBuilder<?> handleClass(Class<?> clazz, List<Type> genericTypes, TypeHandlerManager typeHandlerManager, ParsingContext context, BaseTypeBuilder typeBuilder) { final ObjectTypeBuilder objectType = typeBuilder.objectType(); context.addTypeBuilder(clazz, objectType); fieldHandler.handleFields(clazz, typeHandlerManager, context, objectType); if (clazz.getCanonicalName() != null) { objectType.id(clazz.getCanonicalName()); } objectType.with(new ClassInformationAnnotation(clazz, genericTypes)); return objectType; } }
@Override public TypeBuilder<?> handleClass(Class<?> clazz, List<Type> genericTypes, TypeHandlerManager typeHandlerManager, ParsingContext context, BaseTypeBuilder<?> typeBuilder) { final ObjectTypeBuilder<?> objectType = typeBuilder.objectType(); context.addTypeBuilder(clazz, objectType); fieldHandler.handleFields(clazz, typeHandlerManager, context, objectType); if (clazz.getCanonicalName() != null) { objectType.id(clazz.getCanonicalName()); } objectType.with(new ClassInformationAnnotation(clazz, genericTypes)); return objectType; } }
} else { nullSafeType = new BaseTypeBuilder(JAVA).objectType() .with(new TypeIdAnnotation(nullSafe.defaultImplementingType().getName())) .build();