January 2018
Intermediate to advanced
414 pages
10h 29m
English
Serialization works for complex objects as well. For example, we can create a new class named ComplexObject:
package com.microservices.chapter3data class ComplexObject(var object1 : SimpleObject? = null)
Then, modify our controller to use it:
package com.microservices.chapter3import org.springframework.web.bind.annotation.GetMappingimport org.springframework.web.bind.annotation.RestController@RestControllerclass JsonExamplesController { @GetMapping(value = "/json") fun getJson() = ComplexObject(object1 = SimpleObject("more", "complex"))}
Then, if we request again the URL http://localhost:8080/json, we should get:
{"object1":{"name":"more","place":"complex"}}
Since our ComplexObject is a data class, it will have ...
Read now
Unlock full access