향상된 문서 빌드 - AWS SDK for Java 2.x

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

향상된 문서 빌드

EnhancedDocument는 속성이 중첩된 복잡한 구조를 가진 문서 유형 객체를 나타냅니다. EnhancedDocument에는 DocumentTableSchema에 지정된 기본 키 속성과 일치하는 최상위 속성이 필요합니다. 나머지 내용은 임의적이며 최상위 속성과 깊이 중첩된 속성으로 구성될 수 있습니다.

요소를 추가하는 여러 가지 방법을 제공하는 빌더를 사용하여 EnhancedDocument 인스턴스를 만듭니다.

JSON 문자열로 빌드

JSON 문자열을 사용하면 호출 한 번으로 EnhancedDocument을 만들 수 있습니다. 다음 코드 조각은 jsonPerson() 헬퍼 메서드에서 반환한 JSON 문자열에서 EnhancedDocument를 생성합니다. jsonPerson() 메서드는 이전에 표시된 사람 객체의 JSON 문자열 버전을 반환합니다.

EnhancedDocument document = EnhancedDocument.builder() .json( jsonPerson() ) .build());

개별 요소로 빌드

또는 빌더의 형식이 안전한 메서드를 사용하여 개별 구성 요소에서 EnhancedDocument 인스턴스를 빌드할 수 있습니다.

다음 예제는 이전 예제의 JSON 문자열로 빌드된 향상된 문서와 유사한 person 향상된 문서를 빌드합니다.

/* Define the shape of an address map whose JSON representation looks like the following. Use 'addressMapEnhancedType' in the following EnhancedDocument.builder() to simplify the code. "home": { "zipCode": "00000", "city": "Any Town", "state": "FL", "street": "123 Any Street" }*/ EnhancedType<Map<String, String>> addressMapEnhancedType = EnhancedType.mapOf(EnhancedType.of(String.class), EnhancedType.of(String.class)); // Use the builder's typesafe methods to add elements to the enhanced document. EnhancedDocument personDocument = EnhancedDocument.builder() .putNumber("id", 50) .putString("firstName", "Shirley") .putString("lastName", "Rodriguez") .putNumber("age", 53) .putNull("nullAttribute") .putJson("phoneNumbers", phoneNumbersJSONString()) /* Add the map of addresses whose JSON representation looks like the following. { "home": { "zipCode": "00000", "city": "Any Town", "state": "FL", "street": "123 Any Street" } } */ .putMap("addresses", getAddresses(), EnhancedType.of(String.class), addressMapEnhancedType) .putList("hobbies", List.of("Theater", "Golf"), EnhancedType.of(String.class)) .build();
private static String phoneNumbersJSONString() { return " [" + " {" + " \"type\": \"Home\"," + " \"number\": \"555-0140\"" + " }," + " {" + " \"type\": \"Work\"," + " \"number\": \"555-0155\"" + " }" + " ]"; } private static Map<String, Map<String, String>> getAddresses() { return Map.of( "home", Map.of( "zipCode", "00002", "city", "Any Town", "state", "ME", "street", "123 Any Street")); }