Skip to content

Commit 84aca63

Browse files
committed
Removed primitive boolean getter and replaced with Boolean getter
1 parent 6a4499d commit 84aca63

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/document/EnhancedDocument.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,18 @@ static Builder builder() {
281281
String getJson(String attributeName);
282282

283283
/**
284-
* Gets the boolean value for the specified attribute.
284+
* Gets the {@link Boolean} value for the specified attribute.
285285
*
286286
* @param attributeName Name of the attribute.
287-
* @return value of the specified attribute in the current document as a non-null Boolean.
287+
* @return value of the specified attribute in the current document as a Boolean representation; or null if the attribute
288+
* either doesn't exist or the attribute value is null.
288289
* @throws RuntimeException
289-
* if either the attribute doesn't exist or if the attribute
290-
* value cannot be converted into a boolean value.
290+
* if the attribute value cannot be converted to a Boolean representation.
291+
* Note that the Boolean representation of 0 and 1 in Numbers and "0" and "1" in Strings is false and true,
292+
* respectively.
293+
*
291294
*/
292-
boolean getBoolean(String attributeName);
295+
Boolean getBoolean(String attributeName);
293296

294297

295298
/**

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/document/DefaultEnhancedDocument.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,10 @@ public String getJson(String attributeName) {
189189
}
190190

191191
@Override
192-
public boolean getBoolean(String attributeName) {
192+
public Boolean getBoolean(String attributeName) {
193193
Boolean value = get(attributeName, Boolean.class);
194194
if (value == null) {
195-
throw new IllegalStateException("Value of " + "attribute " + attributeName + " of type null cannot be converted"
196-
+ " into a boolean value");
195+
return null;
197196
}
198197
return value.booleanValue();
199198
}

services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/document/EnhancedDocumentTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,7 @@ void accessingNulAttributeValue() {
407407

408408
Assertions.assertNull(enhancedDocument.getString(NULL_KEY));
409409
Assertions.assertNull(enhancedDocument.getList(NULL_KEY, EnhancedType.of(String.class)));
410-
assertThatIllegalStateException().isThrownBy(() -> enhancedDocument.getBoolean(NULL_KEY))
411-
.withMessage("Value of attribute nullKey of type null cannot be converted into a "
412-
+ "boolean value");
410+
assertThat(enhancedDocument.getBoolean(NULL_KEY)).isNull();
413411

414412
}
415413

0 commit comments

Comments
 (0)