2424import static software .amazon .awssdk .enhanced .dynamodb .document .EnhancedDocumentTestData .testDataInstance ;
2525
2626import com .fasterxml .jackson .core .JsonProcessingException ;
27+ import com .fasterxml .jackson .databind .JsonNode ;
2728import com .fasterxml .jackson .databind .ObjectMapper ;
2829import java .math .BigDecimal ;
2930import java .time .LocalDate ;
5253
5354class EnhancedDocumentTest {
5455
56+ ObjectMapper mapper = new ObjectMapper ();
57+
5558 private static Stream <Arguments > escapeDocumentStrings () {
5659 char c = 0x0a ;
5760 return Stream .of (
@@ -498,7 +501,7 @@ void error_when_usingClassGetPut_for_CollectionValues(){
498501 }
499502
500503 @ Test
501- void toJson_numberFormatting_veryLargeNumbers () {
504+ void toJson_numberFormatting_veryLargeNumbers () throws JsonProcessingException {
502505 EnhancedDocument doc = EnhancedDocument .builder ()
503506 .attributeConverterProviders (defaultProvider ())
504507 .putNumber ("longMax" , Long .MAX_VALUE )
@@ -509,104 +512,124 @@ void toJson_numberFormatting_veryLargeNumbers() {
509512 .build ();
510513
511514 String json = doc .toJson ();
512- assertThat (json ).isEqualTo ("{\" longMax\" :9223372036854775807,\" longMin\" :-9223372036854775808,"
513- + "\" doubleMax\" :1.7976931348623157E308,\" scientific\" :1.23E100,"
514- + "\" manyDecimals\" :1.123456789012345}" );
515+ JsonNode actual = mapper .readTree (json );
516+ JsonNode expected = mapper .readTree ("{\" longMax\" :9223372036854775807,\" longMin\" :-9223372036854775808,"
517+ + "\" doubleMax\" :1.7976931348623157E308,\" scientific\" :1.23E100,"
518+ + "\" manyDecimals\" :1.123456789012345}" );
519+ assertThat (expected ).isEqualTo (actual );
515520 }
516521
517522 @ Test
518- void toJson_numberFormatting_trailingZeros () {
523+ void toJson_numberFormatting_trailingZeros () throws JsonProcessingException {
519524 EnhancedDocument doc = EnhancedDocument .builder ()
520525 .attributeConverterProviders (defaultProvider ())
521526 .putNumber ("twoPointZero" , 2.0 )
522527 .putNumber ("tenPointZeroZero" , 10.00 )
523528 .build ();
524529
525530 String json = doc .toJson ();
526- assertThat (json ).isEqualTo ("{\" twoPointZero\" :2.0,\" tenPointZeroZero\" :10.0}" );
531+ JsonNode actual = mapper .readTree (json );
532+ JsonNode expected = mapper .readTree ("{\" twoPointZero\" :2.0,\" tenPointZeroZero\" :10.0}" );
533+ assertThat (expected ).isEqualTo (actual );
527534 }
528535
529536 @ Test
530- void toJson_stringEscaping_allControlCharacters () {
537+ void toJson_stringEscaping_allControlCharacters () throws JsonProcessingException {
531538 EnhancedDocument doc = EnhancedDocument .builder ()
532539 .attributeConverterProviders (defaultProvider ())
533540 .putString ("allEscapes" , "line1\n line2\t tab\" quote\\ backslash\r \f " )
534541 .build ();
535542
536543 String json = doc .toJson ();
537- assertThat (json ).isEqualTo ("{\" allEscapes\" :\" line1\\ nline2\\ ttab\\ \" quote\\ \\ backslash\\ r\\ f\" }" );
544+ JsonNode actual = mapper .readTree (json );
545+ JsonNode expected = mapper .readTree ("{\" allEscapes\" :\" line1\\ nline2\\ ttab\\ \" quote\\ \\ backslash\\ r\\ f\" }" );
546+ assertThat (expected ).isEqualTo (actual );
538547 }
539548
540549 @ Test
541- void toJson_stringEscaping_forwardSlash () {
550+ void toJson_stringEscaping_forwardSlash () throws JsonProcessingException {
542551 EnhancedDocument doc = EnhancedDocument .builder ()
543552 .attributeConverterProviders (defaultProvider ())
544553 .putString ("slash" , "path/to/resource" )
545554 .build ();
546555
547556 String json = doc .toJson ();
548- assertThat (json ).isEqualTo ("{\" slash\" :\" path/to/resource\" }" );
557+ JsonNode actual = mapper .readTree (json );
558+ JsonNode expected = mapper .readTree ("{\" slash\" :\" path/to/resource\" }" );
559+ assertThat (expected ).isEqualTo (actual );
549560 }
550561
551562 @ Test
552- void toJson_emptyString () {
563+ void toJson_emptyString () throws JsonProcessingException {
553564 EnhancedDocument doc = EnhancedDocument .builder ()
554565 .attributeConverterProviders (defaultProvider ())
555566 .putString ("empty" , "" )
556567 .build ();
557568
558569 String json = doc .toJson ();
559- assertThat (json ).isEqualTo ("{\" empty\" :\" \" }" );
570+ JsonNode actual = mapper .readTree (json );
571+ JsonNode expected = mapper .readTree ("{\" empty\" :\" \" }" );
572+ assertThat (expected ).isEqualTo (actual );
560573 }
561574
562575 @ Test
563- void toJson_bytesEncoding_emptyBytes () {
576+ void toJson_bytesEncoding_emptyBytes () throws JsonProcessingException {
564577 EnhancedDocument doc = EnhancedDocument .builder ()
565578 .attributeConverterProviders (defaultProvider ())
566579 .putBytes ("empty" , SdkBytes .fromByteArray (new byte [0 ]))
567580 .build ();
568581
569582 String json = doc .toJson ();
570- assertThat (json ).isEqualTo ("{\" empty\" :\" \" }" );
583+ JsonNode actual = mapper .readTree (json );
584+ JsonNode expected = mapper .readTree ("{\" empty\" :\" \" }" );
585+ assertThat (expected ).isEqualTo (actual );
571586 }
572587
573588 @ Test
574- void toJson_listWithAllNulls () {
589+ void toJson_listWithAllNulls () throws JsonProcessingException {
575590 EnhancedDocument doc = EnhancedDocument .builder ()
576591 .attributeConverterProviders (defaultProvider ())
577592 .putJson ("nullList" , "[null,null,null]" )
578593 .build ();
579594
580595 String json = doc .toJson ();
581- assertThat (json ).isEqualTo ("{\" nullList\" :[null,null,null]}" );
596+ JsonNode actual = mapper .readTree (json );
597+ JsonNode expected = mapper .readTree ("{\" nullList\" :[null,null,null]}" );
598+ assertThat (expected ).isEqualTo (actual );
582599 }
583600
584601 @ Test
585- void toJson_mapWithNullValues () {
602+ void toJson_mapWithNullValues () throws JsonProcessingException {
586603 EnhancedDocument doc = EnhancedDocument .builder ()
587604 .attributeConverterProviders (defaultProvider ())
588605 .putJson ("nullValues" , "{\" key1\" :null,\" key2\" :\" value\" ,\" key3\" :null}" )
589606 .build ();
590607
591608 String json = doc .toJson ();
592- assertThat (json ).isEqualTo ("{\" nullValues\" :{\" key1\" :null,\" key2\" :\" value\" ,\" key3\" :null}}" );
609+ JsonNode actual = mapper .readTree (json );
610+ JsonNode expected = mapper .readTree ("{\" nullValues\" :{\" key1\" :null,\" key2\" :\" value\" ,\" key3\" :null}}" );
611+ assertThat (expected ).isEqualTo (actual );
593612 }
594613
595614 @ Test
596- void toJson_deeplyNestedStructure () {
597- String deepJson = "{\" level1\" :{\" level2\" :{\" level3\" :{\" level4\" :{\" level5\" :{\" level6\" :{\" level7\" :{\" value\" :\" deep\" }}}}}}}}" ;
615+ void toJson_deeplyNestedStructure () throws JsonProcessingException {
616+ String deepJson = "{\" level1\" :{\" level2\" :{\" level3\" :{\" level4\" :"
617+ + "{\" level5\" :{\" level6\" :{\" level7\" :{\" value\" :\" deep\" }}}}}}}}" ;
598618
599619 EnhancedDocument doc = EnhancedDocument .builder ()
600620 .attributeConverterProviders (defaultProvider ())
601621 .putJson ("nested" , deepJson )
602622 .build ();
603623
604624 String json = doc .toJson ();
605- assertThat (json ).isEqualTo ("{\" nested\" :" + deepJson + "}" );
625+
626+ JsonNode actual = mapper .readTree (json );
627+ JsonNode expected = mapper .readTree ("{\" nested\" :" + deepJson + "}" );
628+ assertThat (expected ).isEqualTo (actual );
606629 }
607630
608631 @ Test
609- void toJson_deeplyNestedArrays () {
632+ void toJson_deeplyNestedArrays () throws JsonProcessingException {
610633 String deepArrayJson = "[[[[[[\" innermost\" ]]]]]]" ;
611634
612635 EnhancedDocument doc = EnhancedDocument .builder ()
@@ -615,7 +638,9 @@ void toJson_deeplyNestedArrays() {
615638 .build ();
616639
617640 String json = doc .toJson ();
618- assertThat (json ).isEqualTo ("{\" nestedArrays\" :" + deepArrayJson + "}" );
641+ JsonNode actual = mapper .readTree (json );
642+ JsonNode expected = mapper .readTree ("{\" nestedArrays\" :" + deepArrayJson + "}" );
643+ assertThat (expected ).isEqualTo (actual );
619644 }
620645
621646 @ Test
0 commit comments