43
43
import org .springframework .core .convert .converter .Converter ;
44
44
import org .springframework .core .serializer .support .SerializingConverter ;
45
45
import org .springframework .data .annotation .Id ;
46
- import org .springframework .data .annotation .Transient ;
47
46
import org .springframework .data .convert .ReadingConverter ;
48
47
import org .springframework .data .convert .WritingConverter ;
49
48
import org .springframework .data .domain .Sort ;
63
62
import org .springframework .data .mongodb .core .query .Criteria ;
64
63
import org .springframework .data .mongodb .core .query .Query ;
65
64
import org .springframework .data .mongodb .core .query .Update ;
65
+ import org .springframework .data .util .TypeInformation ;
66
66
import org .springframework .integration .history .MessageHistory ;
67
67
import org .springframework .integration .message .AdviceMessage ;
68
68
import org .springframework .integration .store .AbstractMessageGroupStore ;
@@ -495,9 +495,9 @@ private long getNextId() {
495
495
Query query = Query .query (Criteria .where ("_id" ).is (SEQUENCE_NAME ));
496
496
query .fields ().include (SEQUENCE );
497
497
return ((Number ) this .template .findAndModify (query ,
498
- new Update ().inc (SEQUENCE , 1L ),
499
- FindAndModifyOptions .options ().returnNew (true ).upsert (true ),
500
- Map .class , this .collectionName )
498
+ new Update ().inc (SEQUENCE , 1L ),
499
+ FindAndModifyOptions .options ().returnNew (true ).upsert (true ),
500
+ Map .class , this .collectionName )
501
501
.get (SEQUENCE )) // NOSONAR - never returns null
502
502
.longValue ();
503
503
}
@@ -589,9 +589,14 @@ public <S> S read(Class<S> clazz, Bson source) {
589
589
if (!MessageWrapper .class .equals (clazz )) {
590
590
return super .read (clazz , source );
591
591
}
592
+
593
+ return (S ) readAsMessageWrapper (source );
594
+ }
595
+
596
+ private MessageWrapper readAsMessageWrapper (Bson source ) {
592
597
if (source != null ) {
593
598
Map <String , Object > sourceMap = asMap (source );
594
- Message <?> message = null ;
599
+ Message <?> message ;
595
600
Object messageType = sourceMap .get ("_messageType" );
596
601
if (messageType == null ) {
597
602
messageType = GenericMessage .class .getName ();
@@ -629,21 +634,30 @@ public <S> S read(Class<S> clazz, Bson source) {
629
634
}
630
635
wrapper .setCondition ((String ) sourceMap .get ("_condition" ));
631
636
632
- return ( S ) wrapper ;
637
+ return wrapper ;
633
638
}
634
639
return null ;
635
640
}
636
641
642
+ @ Override
643
+ @ SuppressWarnings ({ UNCHECKED })
644
+ protected <S > S read (TypeInformation <S > type , Bson source ) {
645
+ if (!MessageWrapper .class .equals (type .getType ())) {
646
+ return super .read (type , source );
647
+ }
648
+
649
+ return (S ) readAsMessageWrapper (source );
650
+ }
651
+
637
652
private Map <String , Object > normalizeHeaders (Map <String , Object > headers ) {
638
653
Map <String , Object > normalizedHeaders = new HashMap <>();
639
654
for (Entry <String , Object > entry : headers .entrySet ()) {
640
655
String headerName = entry .getKey ();
641
656
Object headerValue = entry .getValue ();
642
- if (headerValue instanceof Bson ) {
643
- Bson source = (Bson ) headerValue ;
657
+ if (headerValue instanceof Bson source ) {
644
658
Map <String , Object > document = asMap (source );
645
659
try {
646
- Class <?> typeClass = null ;
660
+ Class <?> typeClass ;
647
661
if (document .containsKey (CLASS )) {
648
662
Object type = document .get (CLASS );
649
663
typeClass = ClassUtils .forName (type .toString (), MongoDbMessageStore .this .classLoader );
@@ -670,8 +684,7 @@ else if (source instanceof BasicDBList) {
670
684
private Object extractPayload (Bson source ) {
671
685
Object payload = asMap (source ).get ("payload" );
672
686
673
- if (payload instanceof Bson ) {
674
- Bson payloadObject = (Bson ) payload ;
687
+ if (payload instanceof Bson payloadObject ) {
675
688
Object payloadType = asMap (payloadObject ).get (CLASS );
676
689
try {
677
690
Class <?> payloadClass =
@@ -845,7 +858,7 @@ private static final class MessageWrapper {
845
858
846
859
private volatile Object _groupId ; // NOSONAR name
847
860
848
- @ Transient
861
+ // @Transient
849
862
private final Message <?> message ; // NOSONAR name
850
863
851
864
@ SuppressWarnings (UNUSED )
0 commit comments