Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How do I design my POJO to enable the correct JSON output ?

 
Ranch Hand
Posts: 717
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi expert,

I am running into another problem.

Guess my Java fundamental is really bad such that I don't know how to handle this case.

Basically, I have a Post endpoint where the @RequestBody is Order order

Now, this Order will have contains a petid

So, I have a constructor as follows:




My apologies I coulnt't get the image out cos the photo is real bad.

When I test out using postman, it will give me :


"quantity" : null // I didn't ask for this so why it will appear ? but quanity is part of the fields in Order class.
"ordertimestamp : "2020-11-17T11:13343"
"status" : "approved"
"complete": false
"id" : null // ? why it will appear null ?



This is what I entered into the body of Postman:


{
 "id" : 11,
 "petid: 3,
 "orderTimestamp" :"2020-11-17T11:13343"
 "status" : approved",
 "complete": false,
 "id" : 2
}




My question is how do i get the petid to show up in postman and why would id - which is order id will appear null ?


[/code]

Any tips, hints are greatly appreciated.  


 
Marshal
Posts: 3355
492
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:How do I design my POJO to enable the correct JSON output ?


What does the POJO look like now?
 
tangara goh
Ranch Hand
Posts: 717
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

tangara goh wrote:How do I design my POJO to enable the correct JSON output ?


What does the POJO look like now?



Hi Ron,






Please let me know what to do in order to let the petId show up.

Is using statis at petId a good idea or ?

Thanking you in advance for your help/hints.
 
Rancher
Posts: 4792
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you feel making petId static is a reasonable change?
What does petId represent, and how does making it static help with that representation?

For the main question, where is that createOrder method used?
Why are you (I think) duplicating the Order, and why are you setting the Order id twice (lines 11 and 13 in your posted code)?
 
tangara goh
Ranch Hand
Posts: 717
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Why do you feel making petId static is a reasonable change?
What does petId represent, and how does making it static help with that representation?

For the main question, where is that createOrder method used?
Why are you (I think) duplicating the Order, and why are you setting the Order id twice (lines 11 and 13 in your posted code)?



Hi Dave,

the createOrder method will be used in Order Controller.

Sorry the line 13 should be setPetId, and not OrderId.  

Now, I have changed the constructor in Pet to use int PetId instead of Pet pet.

I hope to confirm with the experts here whether it is ok to use int petId  or it is advisable not to?

However, I have tried for a few hours using Pet pet inside the Order constructor I just couldn't get the petId ...

Furthermore, this petId will be used in another Controller endpoints so if I don't convert it into static or global variable, will there be a null pointer error problem ?

I am not sure how to test multiple end points in Postman though.

Hope I can have some guidance on the above.

Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic