diff --git a/src/main/java/com/ericsson/eiffel/remrem/producer/controller/ProducerController.java b/src/main/java/com/ericsson/eiffel/remrem/producer/controller/ProducerController.java index 9a47605a..eaad1fc5 100644 --- a/src/main/java/com/ericsson/eiffel/remrem/producer/controller/ProducerController.java +++ b/src/main/java/com/ericsson/eiffel/remrem/producer/controller/ProducerController.java @@ -1,11 +1,12 @@ package com.ericsson.eiffel.remrem.producer.controller; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; + import com.ericsson.eiffel.remrem.producer.helper.ResponseHelper; import com.ericsson.eiffel.remrem.producer.service.MessageService; import com.ericsson.eiffel.remrem.producer.service.SendResult; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import lombok.extern.slf4j.Slf4j; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.RequestBody; @@ -15,9 +16,10 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; +import lombok.extern.slf4j.Slf4j; @Slf4j @RestController @RequestMapping("/producer") public class ProducerController { @@ -26,12 +28,14 @@ @RequestMapping(value = "/msg", method = RequestMethod.POST) @ResponseBody public List send(@RequestParam(value = "rk", required = true) String routingKey, - @RequestBody String body) { + @RequestBody JsonArray body) { log.debug("routingKey: " + routingKey); log.debug("body: " + body); - Type type = new TypeToken>() { - }.getType(); - List msgs = new Gson().fromJson(body, type); + + List msgs = new ArrayList<>(); + for (JsonElement obj : body) { + msgs.add(obj.toString()); + } List results = messageService.send(routingKey, msgs); return responseHelper.convert(results); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d62e08b5..348a6ca6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,3 +7,5 @@ logging.level.com.ericsson.eiffel.remrem.producer=ERROR #rabbitmq.host=127.0.0.1 # must exist #rabbitmq.exchange.name=eiffel.poc + +spring.http.converters.preferred-json-mapper=gson