Update RestUtil
Pembuatan function get json response hanya untuk message label-success
This commit is contained in:
parent
6e03d4b0c6
commit
44b5c0ce4d
@ -20,7 +20,6 @@ import com.google.gson.Gson;
|
||||
public class RestUtil {
|
||||
|
||||
private static final String CONTENT_TYPE = "Content-Type";
|
||||
private static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
|
||||
|
||||
/**
|
||||
* get JSON response from Object
|
||||
@ -33,7 +32,6 @@ public class RestUtil {
|
||||
public static <T> ResponseEntity<T> getJsonResponse(T src) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
//headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return new ResponseEntity<T>(src, headers, HttpStatus.OK);
|
||||
}
|
||||
@ -42,16 +40,17 @@ public class RestUtil {
|
||||
* get JSON response from Object with HTTP status
|
||||
*
|
||||
* @param src
|
||||
* @param status
|
||||
* @param <T>
|
||||
* source class
|
||||
* @return @ResponseEntity
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static <T> ResponseEntity<T> getJsonResponse(T src, HttpStatus status) {
|
||||
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
Map<String,Object> map=new HashMap<String,Object>();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("data", src);
|
||||
return new ResponseEntity(map, headers, status);
|
||||
}
|
||||
@ -64,9 +63,9 @@ public class RestUtil {
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> ResponseEntity<T> getJsonResponse(T src,
|
||||
HttpStatus status, Map<String, String> mapHeaderMessage) {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static <T> ResponseEntity<T> getJsonResponse(T src, HttpStatus status,
|
||||
Map<String, String> mapHeaderMessage) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
@ -76,14 +75,30 @@ public class RestUtil {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String,Object> map=new HashMap<String,Object>();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("messages", mapHeaderMessage);
|
||||
map.put("data", src);
|
||||
//headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return new ResponseEntity(map, headers, status);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param status
|
||||
* @param mapHeaderMessage
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static <T> ResponseEntity<T> getJsonResponse(HttpStatus status, Map<String, String> mapHeaderMessage) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("messages", mapHeaderMessage);
|
||||
|
||||
return new ResponseEntity(map, headers, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* get JSON response from HTTP status only
|
||||
*
|
||||
@ -96,11 +111,8 @@ public class RestUtil {
|
||||
return new ResponseEntity<T>(status);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> ResponseEntity<T> getJsonHttptatus(HttpStatus status,
|
||||
Map<String, String> mapHeaderMessage) {
|
||||
public static <T> ResponseEntity<T> getJsonHttptatus(HttpStatus status, Map<String, String> mapHeaderMessage) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
@ -114,7 +126,7 @@ public class RestUtil {
|
||||
return new ResponseEntity<T>(headers, status);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get JSON response from Set Object
|
||||
*
|
||||
@ -126,11 +138,10 @@ public class RestUtil {
|
||||
public static <T> ResponseEntity<Set<T>> defaultJsonResponse(Set<T> src) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return new ResponseEntity<Set<T>>(src, headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get JSON response from Set Object with custom header
|
||||
*
|
||||
@ -143,16 +154,16 @@ public class RestUtil {
|
||||
public static <T> ResponseEntity<Set<T>> defaultJsonResponse(Set<T> src, Map<String, String> mapHeaderMessage) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
|
||||
if (null != mapHeaderMessage) {
|
||||
for (String key : mapHeaderMessage.keySet()) {
|
||||
headers.add(key, mapHeaderMessage.get(key));
|
||||
}
|
||||
}// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
}
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return new ResponseEntity<Set<T>>(src, headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get JSON response from List Object with custom header
|
||||
*
|
||||
@ -164,19 +175,17 @@ public class RestUtil {
|
||||
*/
|
||||
public static <T> ResponseEntity<List<T>> defaultJsonResponse(List<T> src, Map<String, String> mapHeaderMessage) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
|
||||
if (null != mapHeaderMessage) {
|
||||
for (String key : mapHeaderMessage.keySet()) {
|
||||
headers.add(key, mapHeaderMessage.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return new ResponseEntity<List<T>>(src, headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get JSON response from List Object
|
||||
*
|
||||
@ -188,7 +197,6 @@ public class RestUtil {
|
||||
public static <T> ResponseEntity<List<T>> defaultJsonResponse(List<T> src) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return new ResponseEntity<List<T>>(src, headers, HttpStatus.OK);
|
||||
}
|
||||
@ -204,10 +212,8 @@ public class RestUtil {
|
||||
Gson gson = new Gson();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
headers.set(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return new ResponseEntity<String>(gson.toJson(src), headers,
|
||||
HttpStatus.OK);
|
||||
return new ResponseEntity<String>(gson.toJson(src), headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user