File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed
label-owner-service/api/src/main/java/com/label_owner_service/api Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,8 @@ public PubSubInboundChannelAdapter inboundChannelAdapter(
37
37
);
38
38
adapter .setOutputChannel (messageChannel );
39
39
adapter .setAckMode (AckMode .MANUAL );
40
- adapter .setPayloadType (InitialOwner .class );
40
+ adapter .setPayloadType (String .class );
41
+ //adapter.setPayloadType(InitialOwner.class);
41
42
return adapter ;
42
43
}
43
44
Original file line number Diff line number Diff line change
1
+ package com .label_owner_service .api .listeners ;
2
+
3
+ import com .fasterxml .jackson .databind .ObjectMapper ;
4
+ import com .fasterxml .jackson .databind .json .JsonMapper ;
5
+
6
+ import java .util .concurrent .Callable ;
7
+
8
+ public class DataClassSerialization {
9
+
10
+ static final ObjectMapper MAPPER = JsonMapper .builder ().build ();
11
+
12
+ public static String serialize (Object input ) {
13
+ return unchecked (() -> MAPPER .writeValueAsString (input ));
14
+ }
15
+
16
+ public static <T > T deserialize (String source , Class <T > type ) {
17
+ return unchecked (() -> MAPPER .readValue (source , type ));
18
+ }
19
+
20
+ private static <T > T unchecked (Callable <T > callable ) {
21
+ try {
22
+ return callable .call ();
23
+ } catch (RuntimeException e ) {
24
+ throw e ;
25
+ } catch (Exception e ) {
26
+ throw new RuntimeException (e );
27
+ }
28
+ }
29
+
30
+
31
+ }
Original file line number Diff line number Diff line change @@ -47,13 +47,22 @@ public LabelOwnerListener(LabelOwnerUseCase labelOwnerUseCase) {
47
47
48
48
@ ServiceActivator (inputChannel = "initialOwnerChannel" )
49
49
public void messageReceiver (
50
- InitialOwner initialOwner ,
50
+ String rawInitialOwnerMessage ,
51
+ //InitialOwner initialOwner,
51
52
@ Header (GcpPubSubHeaders .ORIGINAL_MESSAGE ) BasicAcknowledgeablePubsubMessage message
52
53
) {
54
+ InitialOwner initialOwner = parseOwner (rawInitialOwnerMessage );
53
55
labelOwnerUseCase .labelAndSendOwner (initialOwner );
54
56
message .ack ();
55
57
}
56
58
59
+ private InitialOwner parseOwner (String rawInitialOwnerMessage ) {
60
+ String initialOwnerJson = rawInitialOwnerMessage
61
+ .replaceAll ("^.*payload=\\ {" , "{" )
62
+ .replaceAll ("}, headers=.*$" , "}" );
63
+ return DataClassSerialization .deserialize (initialOwnerJson , InitialOwner .class );
64
+ }
65
+
57
66
58
67
59
68
/*
You can’t perform that action at this time.
0 commit comments