Created
March 11, 2020 06:36
-
-
Save junquera/86803ce48361906d69f7a7c77ebf5cd4 to your computer and use it in GitHub Desktop.
Spring basic serialization example
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 io.junquera.ca.back.entities.User; | |
import org.json.JSONObject; | |
import org.springframework.web.bind.annotation.PostMapping; | |
import org.springframework.web.bind.annotation.PutMapping; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
public class LogController { | |
@PostMapping("/user") | |
public void user(@RequestBody User u) throws JsonProcessingException { | |
System.out.println(u.getUsername())); | |
} | |
@PutMapping("/user") | |
public void rawUser(@RequestBody String jsonRaw) throws JsonProcessingException { | |
ObjectMapper mapper=new ObjectMapper(); | |
User u = mapper.readValue(jsonRaw, User.class); | |
JSONObject json = new JSONObject(jsonRaw); | |
System.out.println(json.keySet()); | |
System.out.println("Correct: " + (json.get("username") == u.getUsername())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment