package fr.insee.rmes.api.utils;

import javax.ws.rs.core.MediaType;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

public class ResponseUtils {
	
	private static Logger logger = LogManager.getLogger(ResponseUtils.class);
		
	public static String produceResponse(Object obj, String header) {
		ObjectMapper mapper;
		String response = "";
		if (header == null || header.equals(MediaType.APPLICATION_JSON)) {
			mapper = new ObjectMapper();
		}
		else {
			mapper = new XmlMapper();
		} 
		try {
			response = mapper.writeValueAsString(obj);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return response;
	}

}

@@ -453,16 +453,38 @@
 r mapper
+ = new ObjectMapper();
 ;%0A%09%09Stri
@@ -518,18 +518,18 @@
 der 
-=
+!
 = null 
-%7C%7C
+&&
  hea
@@ -565,12 +565,11 @@
 ION_
-JSON
+XML
 )) %7B
@@ -577,38 +577,35 @@
 %09%09%09mapper = new 
-Object
+Xml
 Mapper();%0A%09%09%7D%0A%09%09
@@ -619,35 +619,38 @@
 %09%09%09mapper = new 
-Xml
+Object
 Mapper();%0A%09%09%7D %0A%09

Set default accept header to json