Last active
April 2, 2021 04:12
-
-
Save douglarek/add51e3781c239c525373a7f7464185c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.annotation.JsonProperty; | |
import com.fasterxml.jackson.core.JsonParser.Feature; | |
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
public class ResponseEntity<T> { | |
private static final ObjectMapper mapper = new ObjectMapper(); | |
private int code; | |
@JsonProperty("msg") | |
private String message; | |
private T data; | |
public int getCode() { | |
return code; | |
} | |
public void setCode(final int code) { | |
this.code = code; | |
} | |
public String getMessage() { | |
return message; | |
} | |
public void setMessage(final String message) { | |
this.message = message; | |
} | |
public T getData() { | |
return data; | |
} | |
public void setData(final T data) { | |
this.data = data; | |
} | |
public static <T> ResponseEntity<T> fromContent(final String content, Class<T> valueType) { | |
try { | |
return mapper.readValue(content, | |
mapper.getTypeFactory().constructParametricType(ResponseEntity.class, valueType)); | |
} catch (JsonProcessingException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment