#Endpoint return with Map - Spring Boot

19 messages · Page 1 of 1 (latest)

trail nebulaBOT
#

Hey, @obsidian swallow!
Please remember to /close this post once your question has been answered!

obsidian swallow
#

Example of other returns in the same method:

{ "destination": { "id": "100", "balance": 10 } }

#

By the way, I can't create different endpoints because the business rule don't does not allow. The same endpoint with the same HTTP method should return different objects depending of the input

warped totem
#

......... A Map can contain as many objects as you want

#

Note that with the example given, I don't quite see why you can't return an OriginAndDestination rather than a Map

obsidian swallow
warped totem
#

What do you mean?

obsidian swallow
warped totem
#

Well give a Map<String, Object> rather than something else

obsidian swallow
#

And there is others return in the same method where is returned a Map<String, Object>

warped totem
#

Dude, key, and value

#

Map<String, Object> means you can put as many objects as you want, each associated with its own String

#

Clearer?

obsidian swallow
#

Because I think this is the object:

{
"origin":
{
"id":"100",
"balance": 0
},
"destination":
{
"id": "300",
"balance": 15
}
}

But, what is the key?

warped totem
#

response.put("origin", origin);

#

response.put("destination", destination);