Rev 24383 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.util;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.ObjectMapper;import com.spice.profitmandi.common.ResponseCodeHolder;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import java.util.HashMap;import java.util.Map;@Componentpublic class MVCResponseSender {private static final Logger LOGGER = LogManager.getLogger(MVCResponseSender.class);@AutowiredObjectMapper objectMapper;public String createResponseString(String responseCode, boolean status, String redirectUrl) throws Exception {Map<String, Object> response = new HashMap<>();response.put("message", ResponseCodeHolder.getMessage(responseCode));response.put("status", status);response.put("redirectUrl", redirectUrl);try {return objectMapper.writeValueAsString(response);} catch (JsonProcessingException e) {LOGGER.error("Error occured while converting response to json", e);throw e;}}public String createResponseString(String responseCode, boolean status, String redirectUrl, String name) throws Exception {Map<String, Object> response = new HashMap<>();response.put("message", ResponseCodeHolder.getMessage(responseCode));response.put("status", status);response.put("redirectUrl", redirectUrl);response.put("name",name);try {return objectMapper.writeValueAsString(response);} catch (JsonProcessingException e) {LOGGER.error("Error occured while converting response to json", e);throw e;}}public String createResponseString(Object object) throws Exception {try {return objectMapper.writeValueAsString(object);} catch (JsonProcessingException e) {LOGGER.error("Error occured while converting response to json", e);throw e;}}}