V
V
Vitaly Khvan2021-08-05 13:41:29
Java
Vitaly Khvan, 2021-08-05 13:41:29

What pattern should be used to define generic json-a in java?

There are several types of json objects that should come to 1 controller

@PostMapping("/")
    public void execute(@Valid @RequestBody ExecuteRequest request) {
           
    }

public class ExecuteRequest {
    @NotBlank
    private String method;
    @NotBlank
    private Object payload;
}


the necessary method will always come to method, but different data should come to payload depending on the method, how should this be described? It can be just about, because I don't even know how to write a request to google.

json examples

{"method": "cd", "payload": {"method": "create", "name": "testCd"}}
{"method": "file", "payload": {"method" : "create", "name": "testCd", "path": "D:/"}}
{"method": "cloud", "payload": {"name": "test name", "url" : "cloudUrl"}}

i.e. fields may or may not be present.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-08-05
@xRites

https://github.com/FasterXML/jackson-docs/wiki/Jac...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question