{"id":124053,"date":"2024-06-21T16:20:07","date_gmt":"2024-06-21T13:20:07","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=124053"},"modified":"2024-06-20T13:34:00","modified_gmt":"2024-06-20T10:34:00","slug":"spring-mockmvc-get-json-as-object","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html","title":{"rendered":"Spring MockMVC Get JSON As Object"},"content":{"rendered":"<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p><a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/testing\/spring-mvc-test-framework.html\" target=\"_blank\" rel=\"noreferrer noopener\">Spring MockMVC<\/a> is the Spring MVC testing framework which performs Spring MVC request handling and response asserting via mocking request and response objects without a running HTTP server. @<a href=\"https:\/\/docs.spring.io\/spring-boot\/api\/java\/org\/springframework\/boot\/test\/autoconfigure\/web\/servlet\/AutoConfigureMockMvc.html\" target=\"_blank\" rel=\"noreferrer noopener\">AutoConfigureMockMvc<\/a> is used to configure and a <a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/test\/web\/servlet\/MockMvc.html\" target=\"_blank\" rel=\"noreferrer noopener\">MockMVC<\/a> instance is injected into a test class. In this example, I will demonstrate Spring MockMVC fetch JSON by creating a simple Get Rest API and mocking the response via MockMVC and then converting the response string to an object via both <a href=\"https:\/\/github.com\/FasterXML\/jackson-docs\" target=\"_blank\" rel=\"noreferrer noopener\">Jackson<\/a> and <a href=\"https:\/\/www.javadoc.io\/doc\/com.google.code.gson\/gson\/2.8.0\/com\/google\/gson\/Gson.html\" target=\"_blank\" rel=\"noreferrer noopener\">GSON<\/a> libraries.<\/p>\n<h2 class=\"wp-block-heading\">2. Setup<\/h2>\n<p>In this step, I will create a gradle project with <code>spring-boot-starter-web<\/code>,  <code>Jackson<\/code>, <code>GSON<\/code>, <code>Lombok<\/code>, and <code>Junit<\/code> libraries.<\/p>\n<p><span style=\"text-decoration: underline\"><em>build.gradle<\/em><\/span><\/p>\n<pre class=\"brush:plain\">plugins {\n\tid 'java'\n\tid 'org.springframework.boot' version '3.3.0'\n\tid 'io.spring.dependency-management' version '1.1.5'\n}\n\ngroup = 'com.zheng.demo.sbtest'\nversion = '0.0.1-SNAPSHOT'\n\njava {\n\ttoolchain {\n\t\tlanguageVersion = JavaLanguageVersion.of(17)\n\t}\n}\n\nconfigurations {\n  compileOnly {\n    extendsFrom annotationProcessor\n  }\n}\n\nrepositories {\n\tmavenCentral()\n}\n\ndependencies {\n\timplementation 'org.springframework.boot:spring-boot-starter-web'\n\t\n\tcompileOnly 'org.projectlombok:lombok'\n\tannotationProcessor 'org.projectlombok:lombok'\n\t\n\timplementation 'com.google.code.gson:gson:2.11.0'\n\t\n\ttestImplementation 'org.springframework.boot:spring-boot-starter-test'\n\ttestRuntimeOnly 'org.junit.platform:junit-platform-launcher'\n}\n\ntasks.named('test') {\n\tuseJUnitPlatform()\n}\n<\/pre>\n<h2 class=\"wp-block-heading\">3. Get Rest API<\/h2>\n<h3 class=\"wp-block-heading\"><a name=\"step31\"><\/a>3.1 MyRestController<\/h3>\n<p>In this step, I will create a <code>MyRestController.java<\/code> class which has a <code>Get<\/code> method to return a <code>RestReturnData<\/code> <code>ResponseEntity<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>MyRestController.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[18,19]\">package com.zheng.demo.sbtest.demo.rest;\n\nimport java.util.stream.IntStream;\n\nimport org.springframework.http.HttpStatus;\nimport org.springframework.http.ResponseEntity;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport com.zheng.demo.sbtest.demo.data.RestReturnData;\n\n@RestController\npublic class MyRestController {\n\n\t@GetMapping(\"\/\")\n\tpublic ResponseEntity&lt;RestReturnData&gt; getJsonResponse(@RequestParam(\"input\") String input) {\n\t\tRestReturnData retD = new RestReturnData(IntStream.range(0, input.length()).map(n -&gt; (n + 1) * 3).toArray(),\n\t\t\t\tinput.length(), input);\n\n\t\treturn new ResponseEntity&lt;RestReturnData&gt;(retD, HttpStatus.OK);\n\t}\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 18,19: the Get API response is a dummy data generated from the <code>input<\/code> value.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">3.2 Response Data<\/h3>\n<p>In this step, I will create a <code>RestReturnData.java<\/code> class which is used at <a href=\"#step31\">step 3.1<\/a>. <\/p>\n<p><span style=\"text-decoration: underline\"><em>RestReturnData.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.zheng.demo.sbtest.demo.data;\n\nimport lombok.AllArgsConstructor;\nimport lombok.Data;\nimport lombok.NoArgsConstructor;\n\n@Data\n@NoArgsConstructor\n@AllArgsConstructor\npublic class RestReturnData {\n\tprivate int[] someIntArray;\n\tprivate int someNumber;\n\tprivate String someString;\n}\n<\/pre>\n<p><strong>Note<\/strong>: use the Lombok annotations to reduce the boilerplate code.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3 class=\"wp-block-heading\">3.3 Spring Boot Application<\/h3>\n<p>In this step, I will create a <code>DemoApplication.java<\/code> annotated with <code>@SpringBootApplication<\/code>. <strong>Note<\/strong>: if the project is generated from the <a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Spring initializr<\/a>, then no modification is needed.<\/p>\n<p><span style=\"text-decoration: underline\"><em>DemoApplication.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.zheng.demo.sbtest.demo;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class DemoApplication {\n\tpublic static void main(String[] args) {\n\t\tSpringApplication.run(DemoApplication.class, args);\n\t}\n}\n<\/pre>\n<p>Start the Spring boot application and navigate to <a href=\"http:\/\/localhost:8080\/?input=hello\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/localhost:8080\/?input=hello<\/a> and capture the result in the following screenshot.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/app.jpg\"><img decoding=\"async\" width=\"465\" height=\"238\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/app.jpg\" alt=\"\" class=\"wp-image-124120\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/app.jpg 465w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/app-300x154.jpg 300w\" sizes=\"(max-width: 465px) 100vw, 465px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 1. Get API<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">4. Test Spring MockMVC Fetch JSON<\/h2>\n<h3 class=\"wp-block-heading\">4.1 DemoApplicationTests<\/h3>\n<p>In this step, I will run the generated <code>DemoApplicationTests.java<\/code> to ensure that the spring boot application is wired correctly. <strong>Note<\/strong>: no modification is needed here.<\/p>\n<p><span style=\"text-decoration: underline\"><em>DemoApplicationTests.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.zheng.demo.sbtest.demo;\n\nimport org.junit.jupiter.api.Test;\nimport org.springframework.boot.test.context.SpringBootTest;\n\n@SpringBootTest\nclass DemoApplicationTests {\n\t@Test\n\tvoid contextLoads() {\n\t}\n}\n<\/pre>\n<h3 class=\"wp-block-heading\">4.2 Spring MockMVC Test<\/h3>\n<p>In this step, I will create a <code>MyRestControllerTest.java<\/code> class which tests the <code>Get<\/code> API created at <a href=\"#step31\">step 3.1<\/a>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>MyRestControllerTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;highlight:[16,20,24]\">package com.zheng.demo.sbtest.demo.rest;\n\nimport static org.hamcrest.Matchers.containsString;\nimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\nimport static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;\n\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;\nimport org.springframework.boot.test.context.SpringBootTest;\nimport org.springframework.test.web.servlet.MockMvc;\n\n@SpringBootTest\n@AutoConfigureMockMvc\nclass MyRestControllerTest {\n\n\t@Autowired\n\tprivate MockMvc mockMvc;\n\n\t@Test\n\tvoid shouldReturnDefaultMessage() throws Exception {\n\t\tthis.mockMvc.perform(get(\"\/?input=hello\")).andDo(print()).andExpect(status().isOk())\n\t\t\t\t.andExpect(content().string(containsString(\"hello\")));\n\t}\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 16: <code>@AutoConfigureMockMvc<\/code> is configured.<\/li>\n<li>Line 20: a <code>MockMvc<\/code> is autowired by Spring.<\/li>\n<li>Line 24: the mocked instance performs the Get API and response is asserted.<\/li>\n<\/ul>\n<p>Run this test and capture the output here.<\/p>\n<p><span style=\"text-decoration: underline\"><em>MyRestControllerTest output<\/em><\/span><\/p>\n<pre class=\"brush:plain; highlight:[6,34,35]\">2024-06-18T20:56:06.922-05:00  INFO 21400 --- [demo] [           main] c.z.d.s.demo.rest.MyRestControllerTest   : Started MyRestControllerTest in 1.587 seconds (process running for 2.604)\n\nMockHttpServletRequest:\n      HTTP Method = GET\n      Request URI = \/\n       Parameters = {input=[hello]}\n          Headers = []\n             Body = null\n    Session Attrs = {}\n\nHandler:\n             Type = com.zheng.demo.sbtest.demo.rest.MyRestController\n           Method = com.zheng.demo.sbtest.demo.rest.MyRestController#getJsonResponse(String)\n\nAsync:\n    Async started = false\n     Async result = null\n\nResolved Exception:\n             Type = null\n\nModelAndView:\n        View name = null\n             View = null\n            Model = null\n\nFlashMap:\n       Attributes = null\n\nMockHttpServletResponse:\n           Status = 200\n    Error message = null\n          Headers = [Content-Type:\"application\/json\"]\n     Content type = application\/json\n             Body = {\"someIntArray\":[3,6,9,12,15],\"someNumber\":5,\"someString\":\"hello\"}\n    Forwarded URL = null\n   Redirected URL = null\n          Cookies = []\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 6: the <code>Get<\/code> request query parameter.<\/li>\n<li>Line 34,35: the <code>Get<\/code> response Json string.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">4.3 Spring MockMVC Fetch Json via Gson<\/h3>\n<p>In this step, I will create a <code>TestMockMvcViaGson.java<\/code> test class which converts the mocked Rest <code>Get<\/code> response into POJO via the Gson library.<\/p>\n<p><span style=\"text-decoration: underline\"><em>TestMockMvcViaGson.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[29,30]\">package com.zheng.demo.sbtest.demo.rest;\n\nimport static org.junit.jupiter.api.Assertions.assertEquals;\nimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\nimport static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;\n\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;\nimport org.springframework.boot.test.context.SpringBootTest;\nimport org.springframework.test.web.servlet.MockMvc;\n\nimport com.google.gson.Gson;\nimport com.zheng.demo.sbtest.demo.data.RestReturnData;\n\n@SpringBootTest\n@AutoConfigureMockMvc\nclass TestMockMvcViaGson {\n\n\t@Autowired\n\tprivate MockMvc mockMvc;\n\n\t@Test\n\tvoid use_Gson_to_map_JsonString() {\n\t\ttry {\n\t\t\tString resultString = mockMvc.perform(get(\"\/\").param(\"input\", \"test_user\")).andDo(print())\n\t\t\t\t\t.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();\n\t\t\tGson gson = new Gson();\n\t\t\tRestReturnData someClass = gson.fromJson(resultString, RestReturnData.class);\n\t\t\tassertEquals(\"test_user\", someClass.getSomeString());\n\t\t\tassertEquals(9, someClass.getSomeNumber());\n\t\t\tassertEquals(27, someClass.getSomeIntArray()[8]);\n\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 29: create a <code>gson<\/code> instance.<\/li>\n<li>Line 30: convert the JSON string to a Java object via <code>gson<\/code>.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">4.4 Spring MockMvc Fetch Json via Jackson<\/h3>\n<p>In this step, I will create a <code>TestMockMvcViaJackson.java<\/code> test class which converts the mocked Rest <code>Get<\/code> response to POJO via Jackson&#8217;s <code>objectMapper<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>TestMockMvcViaJackson.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[30]\">package com.zheng.demo.sbtest.demo.rest;\n\nimport static org.junit.jupiter.api.Assertions.assertEquals;\nimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\nimport static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;\n\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;\nimport org.springframework.boot.test.context.SpringBootTest;\nimport org.springframework.test.web.servlet.MockMvc;\n\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.zheng.demo.sbtest.demo.data.RestReturnData;\n\n@SpringBootTest\n@AutoConfigureMockMvc\nclass TestMockMvcViaJackson {\n\n\t@Autowired\n\tprivate MockMvc mockMvc;\n\n\t@Test\n\tvoid use_ObjectMapper_to_map_JsonString() {\n\t\ttry {\n\t\t\tString resultString = mockMvc.perform(get(\"\/\").param(\"input\", \"test_user\")).andDo(print())\n\t\t\t\t\t.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();\n\n\t\t\tRestReturnData someClass = new ObjectMapper().readValue(resultString, RestReturnData.class);\n\t\t\tassertEquals(\"test_user\", someClass.getSomeString());\n\t\t\tassertEquals(9, someClass.getSomeNumber());\n\t\t\tassertEquals(27, someClass.getSomeIntArray()[8]);\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\n\t}\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 30: convert the Json string to a Java object via Jackson&#8217;s <code>objectMapper<\/code>.<\/li>\n<\/ul>\n<p>Run the Junit tests and capture the results as the following screenshot.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/tests-4.jpg\"><img decoding=\"async\" width=\"800\" height=\"478\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/tests-4.jpg\" alt=\"\" class=\"wp-image-124082\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/tests-4.jpg 800w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/tests-4-300x179.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/tests-4-768x459.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 2, Test Results<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">5. Conclusion<\/h2>\n<p>In this example, I created a Rest Get API via Spring <code>@RestController<\/code> and tested it via Spring MockMVC. I also converted the Rest API&#8217;s JSON string into POJO via both Jackson and Gson libraries.<\/p>\n<h2 class=\"wp-block-heading\">6. Download<\/h2>\n<p>This was an example of a gradle project.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/06\/sbtest-demo.zip\"><strong>Spring MockMVC Get JSON As Object<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Spring MockMVC is the Spring MVC testing framework which performs Spring MVC request handling and response asserting via mocking request and response objects without a running HTTP server. @AutoConfigureMockMvc is used to configure and a MockMVC instance is injected into a test class. In this example, I will demonstrate Spring MockMVC fetch JSON &hellip;<\/p>\n","protected":false},"author":128892,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[128,162,69,854,2032],"class_list":["post-124053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-gson","tag-jackson","tag-json","tag-spring-boot","tag-spring-mock"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring MockMVC Get JSON As Object - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about spring mockmvc fetch json? Then check out our detailed example.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring MockMVC Get JSON As Object - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about spring mockmvc fetch json? Then check out our detailed example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-21T13:20:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mary Zheng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mary Zheng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html\"},\"author\":{\"name\":\"Mary Zheng\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\"},\"headline\":\"Spring MockMVC Get JSON As Object\",\"datePublished\":\"2024-06-21T13:20:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html\"},\"wordCount\":469,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Gson\",\"Jackson\",\"JSON\",\"Spring Boot\",\"spring Mock\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html\",\"name\":\"Spring MockMVC Get JSON As Object - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2024-06-21T13:20:07+00:00\",\"description\":\"Interested to learn more about spring mockmvc fetch json? Then check out our detailed example.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/spring-mockmvc-get-json-as-object.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring MockMVC Get JSON As Object\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\",\"name\":\"Mary Zheng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"caption\":\"Mary Zheng\"},\"description\":\"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/mary-zheng\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring MockMVC Get JSON As Object - Java Code Geeks","description":"Interested to learn more about spring mockmvc fetch json? Then check out our detailed example.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html","og_locale":"en_US","og_type":"article","og_title":"Spring MockMVC Get JSON As Object - Java Code Geeks","og_description":"Interested to learn more about spring mockmvc fetch json? Then check out our detailed example.","og_url":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2024-06-21T13:20:07+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Mary Zheng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mary Zheng","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html"},"author":{"name":"Mary Zheng","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5"},"headline":"Spring MockMVC Get JSON As Object","datePublished":"2024-06-21T13:20:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html"},"wordCount":469,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Gson","Jackson","JSON","Spring Boot","spring Mock"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html","url":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html","name":"Spring MockMVC Get JSON As Object - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2024-06-21T13:20:07+00:00","description":"Interested to learn more about spring mockmvc fetch json? Then check out our detailed example.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/spring-mockmvc-get-json-as-object.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring MockMVC Get JSON As Object"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5","name":"Mary Zheng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","caption":"Mary Zheng"},"description":"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.","sameAs":["https:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/mary-zheng"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/124053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/128892"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=124053"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/124053\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=124053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=124053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=124053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}