Skip to content

Commit df11817

Browse files
committed
Merge pull request #7 from vitalca/master
String has been replaced with JsonArray
2 parents 1de05d8 + 55b80b9 commit df11817

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/main/java/com/ericsson/eiffel/remrem/producer/controller/ProducerController.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.ericsson.eiffel.remrem.producer.controller;
22

3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
5+
36
import com.ericsson.eiffel.remrem.producer.helper.ResponseHelper;
47
import com.ericsson.eiffel.remrem.producer.service.MessageService;
58
import com.ericsson.eiffel.remrem.producer.service.SendResult;
6-
import com.google.gson.Gson;
7-
import com.google.gson.reflect.TypeToken;
8-
import lombok.extern.slf4j.Slf4j;
9+
910
import org.springframework.beans.factory.annotation.Autowired;
1011
import org.springframework.beans.factory.annotation.Qualifier;
1112
import org.springframework.web.bind.annotation.RequestBody;
@@ -15,9 +16,10 @@
1516
import org.springframework.web.bind.annotation.ResponseBody;
1617
import org.springframework.web.bind.annotation.RestController;
1718

18-
import java.lang.reflect.Type;
19+
import java.util.ArrayList;
1920
import java.util.List;
2021

22+
import lombok.extern.slf4j.Slf4j;
2123

2224
@Slf4j @RestController @RequestMapping("/producer") public class ProducerController {
2325

@@ -26,12 +28,14 @@
2628

2729
@RequestMapping(value = "/msg", method = RequestMethod.POST) @ResponseBody
2830
public List<String> send(@RequestParam(value = "rk", required = true) String routingKey,
29-
@RequestBody String body) {
31+
@RequestBody JsonArray body) {
3032
log.debug("routingKey: " + routingKey);
3133
log.debug("body: " + body);
32-
Type type = new TypeToken<List<String>>() {
33-
}.getType();
34-
List<String> msgs = new Gson().fromJson(body, type);
34+
35+
List<String> msgs = new ArrayList<>();
36+
for (JsonElement obj : body) {
37+
msgs.add(obj.toString());
38+
}
3539
List<SendResult> results = messageService.send(routingKey, msgs);
3640
return responseHelper.convert(results);
3741
}

src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ logging.level.com.ericsson.eiffel.remrem.producer=ERROR
77
#rabbitmq.host=127.0.0.1
88
# must exist
99
#rabbitmq.exchange.name=eiffel.poc
10+
11+
spring.http.converters.preferred-json-mapper=gson

0 commit comments

Comments
 (0)