Created
April 15, 2020 11:57
-
-
Save iamvickyav/3701fafc985f303d370e0e862daf7d11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.databind.ObjectMapper; | |
import org.springframework.http.MediaType; | |
import org.springframework.util.ResourceUtils; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.Map; | |
@RestController | |
public class MyController { | |
// Approach 1 : Drawback - Need to manually convert JSON to String using external website | |
// https://tools.knowledgewalls.com/jsontostring | |
@GetMapping(value = "/test1", produces = MediaType.APPLICATION_JSON_VALUE) | |
String processRequest(){ | |
return "{\"request\":{\"1\":[{\"apiId\":1,\"newQuota\":12},{\"apiId\":2,\"newQuota\":12}]}}"; | |
} | |
// Approach 2 : Drawback - Needs to create .json file under resources folder for every JSON | |
@GetMapping(value = "/test2") | |
Map processRequest2() throws IOException { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
File file = ResourceUtils.getFile("classpath:order.json"); | |
return objectMapper.readValue(file, Map.class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment