Source:
<code>public static void deIdentifyWithMasking(String projectId, String textToDeIdentify) throws IOException { try (DlpServiceClient dlp = DlpServiceClient.create()) { ContentItem contentItem = ContentItem.newBuilder().setValue(textToDeIdentify).build(); List<InfoType> infoTypes = <START> Stream.of("US_SOCIAL_SECURITY_NUMBER") <END> .map(it -> InfoType.newBuilder().setName(it).build()) .collect(Collectors.toList()); InspectConfig inspectConfig = InspectConfig.newBuilder().addAllInfoTypes(infoTypes).build(); CharacterMaskConfig characterMaskConfig = CharacterMaskConfig.newBuilder() .setMaskingCharacter("X") .setNumberToMask(5) .build(); PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder() .setReplaceWithInfoTypeConfig(ReplaceWithInfoTypeConfig.getDefaultInstance()) .build(); InfoTypeTransformation infoTypeTransformation = InfoTypeTransformation.newBuilder() .setPrimitiveTransformation(primitiveTransformation) .build(); InfoTypeTransformations transformations = InfoTypeTransformations.newBuilder().addTransformations(infoTypeTransformation).build(); DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().setInfoTypeTransformations(transformations).build(); DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder() .setParent(ProjectName.of(projectId).toString()) .setItem(contentItem) .setInspectConfig(inspectConfig) .setDeidentifyConfig(deidentifyConfig) .build(); DeidentifyContentResponse response = dlp.deidentifyContent(request); System.out.println("Text after masking: " + response.getItem().getValue()); } }</code><technical_language>this stream/list creation instead of adding single info type in other examples</technical_language>

Target:
public static void deIdentifyWithMasking(String projectId, String textToDeIdentify) throws IOException { try (DlpServiceClient dlp = DlpServiceClient.create()) { ContentItem contentItem = ContentItem.newBuilder().setValue(textToDeIdentify).build(); InfoType infoType = InfoType.newBuilder().setName("US_SOCIAL_SECURITY_NUMBER").build(); InspectConfig inspectConfig = InspectConfig.newBuilder().addAllInfoTypes(Arrays.asList(infoType)).build(); CharacterMaskConfig characterMaskConfig = CharacterMaskConfig.newBuilder() .setMaskingCharacter("X") .setNumberToMask(5) .build(); PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder() .setReplaceWithInfoTypeConfig(ReplaceWithInfoTypeConfig.getDefaultInstance()) .build(); InfoTypeTransformation infoTypeTransformation = InfoTypeTransformation.newBuilder() .setPrimitiveTransformation(primitiveTransformation) .build(); InfoTypeTransformations transformations = InfoTypeTransformations.newBuilder().addTransformations(infoTypeTransformation).build(); DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().setInfoTypeTransformations(transformations).build(); DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder() .setParent(ProjectName.of(projectId).toString()) .setItem(contentItem) .setInspectConfig(inspectConfig) .setDeidentifyConfig(deidentifyConfig) .build(); DeidentifyContentResponse response = dlp.deidentifyContent(request); System.out.println("Text after masking: " + response.getItem().getValue()); } }