@@ -496,4 +496,122 @@ void error_when_usingClassGetPut_for_CollectionValues(){
496496 () -> EnhancedDocument .builder ().build ().get ("listKey" , List .class ))
497497 .withMessage ("Values of type List are not supported by this API, please use the getList API instead" );
498498 }
499+
500+ @ Test
501+ void toJson_numberFormatting_veryLargeNumbers () {
502+ EnhancedDocument doc = EnhancedDocument .builder ()
503+ .attributeConverterProviders (defaultProvider ())
504+ .putNumber ("longMax" , Long .MAX_VALUE )
505+ .putNumber ("longMin" , Long .MIN_VALUE )
506+ .putNumber ("doubleMax" , Double .MAX_VALUE )
507+ .putNumber ("scientific" , 1.23e+100 )
508+ .putNumber ("manyDecimals" , 1.123456789012345 )
509+ .build ();
510+
511+ String json = doc .toJson ();
512+ assertThat (json ).isNotNull ();
513+ }
514+
515+ @ Test
516+ void toJson_numberFormatting_trailingZeros () {
517+ EnhancedDocument doc = EnhancedDocument .builder ()
518+ .attributeConverterProviders (defaultProvider ())
519+ .putNumber ("twoPointZero" , 2.0 )
520+ .putNumber ("tenPointZeroZero" , 10.00 )
521+ .build ();
522+
523+ String json = doc .toJson ();
524+ assertThat (json ).isNotNull ();
525+ }
526+
527+ @ Test
528+ void toJson_stringEscaping_allControlCharacters () {
529+ EnhancedDocument doc = EnhancedDocument .builder ()
530+ .attributeConverterProviders (defaultProvider ())
531+ .putString ("allEscapes" , "line1\n line2\t tab\" quote\\ backslash\r \f " )
532+ .build ();
533+
534+ String json = doc .toJson ();
535+ assertThat (json ).contains ("\\ n" ).contains ("\\ t" ).contains ("\\ \" " ).contains ("\\ \\ " );
536+ }
537+
538+ @ Test
539+ void toJson_stringEscaping_forwardSlash () {
540+ EnhancedDocument doc = EnhancedDocument .builder ()
541+ .attributeConverterProviders (defaultProvider ())
542+ .putString ("slash" , "path/to/resource" )
543+ .build ();
544+
545+ String json = doc .toJson ();
546+ assertThat (json ).isNotNull ();
547+ }
548+
549+ @ Test
550+ void toJson_emptyString () {
551+ EnhancedDocument doc = EnhancedDocument .builder ()
552+ .attributeConverterProviders (defaultProvider ())
553+ .putString ("empty" , "" )
554+ .build ();
555+
556+ String json = doc .toJson ();
557+ assertThat (json ).contains ("\" empty\" :\" \" " );
558+ }
559+
560+ @ Test
561+ void toJson_bytesEncoding_emptyBytes () {
562+ EnhancedDocument doc = EnhancedDocument .builder ()
563+ .attributeConverterProviders (defaultProvider ())
564+ .putBytes ("empty" , SdkBytes .fromByteArray (new byte [0 ]))
565+ .build ();
566+
567+ String json = doc .toJson ();
568+ assertThat (json ).isNotNull ();
569+ }
570+
571+ @ Test
572+ void toJson_bytesEncoding_largeBytes () {
573+ byte [] largeArray = new byte [10000 ];
574+ Arrays .fill (largeArray , (byte ) 65 ); // Fill with 'A'
575+
576+ EnhancedDocument doc = EnhancedDocument .builder ()
577+ .attributeConverterProviders (defaultProvider ())
578+ .putBytes ("large" , SdkBytes .fromByteArray (largeArray ))
579+ .build ();
580+
581+ String json = doc .toJson ();
582+ assertThat (json ).isNotNull ();
583+ }
584+
585+ @ Test
586+ void toJson_listWithAllNulls () {
587+ EnhancedDocument doc = EnhancedDocument .builder ()
588+ .attributeConverterProviders (defaultProvider ())
589+ .putJson ("nullList" , "[null,null,null]" )
590+ .build ();
591+
592+ String json = doc .toJson ();
593+ assertThat (json ).contains ("[null,null,null]" );
594+ }
595+
596+ @ Test
597+ void toJson_mapWithSpecialCharKeys () {
598+ EnhancedDocument doc = EnhancedDocument .builder ()
599+ .attributeConverterProviders (defaultProvider ())
600+ .putJson ("specialKeys" , "{\" key with spaces\" :1,\" key\\ \" with\\ \" quotes\" :2,\" key/with/slash\" :3}" )
601+ .build ();
602+
603+ String json = doc .toJson ();
604+ assertThat (json ).isNotNull ();
605+ }
606+
607+ @ Test
608+ void toJson_mapWithNullValues () {
609+ EnhancedDocument doc = EnhancedDocument .builder ()
610+ .attributeConverterProviders (defaultProvider ())
611+ .putJson ("nullValues" , "{\" key1\" :null,\" key2\" :\" value\" ,\" key3\" :null}" )
612+ .build ();
613+
614+ String json = doc .toJson ();
615+ assertThat (json ).contains ("null" );
616+ }
499617}
0 commit comments