Search code examples
jsonspring-bootuuidunique-id

generate unique Id and request params for post api


I've a scenario where my json object should look like

{
"domainObject" :{
    "amount" : "1230798373024",
    "business" : "n/a",
    "productGroup" : "n/a",
    "productType" : "n/a",
    "balanceType" : "n/a", 
    "balanceSubType" : "n/a"       
},
   "uniqueId" : "test1",
    "userId" : "user1"
}

I've 2 questions:

  1. I'm confused if I should create 2 DTOs, one for domainObject and another for entire object or is there any better way around?
  2. I want to generate a different id(uniqueId) for every request, what should be the better option, given that this api would be triggered around few 100 times a day. Should I use random UUID but then is there any assurance these id's won't collide or is there any better way around?

Solution

    1. I would create two objects
    2. UUIDs don't collide, by design. They are "Universally Unique IDs".