Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference in output between toString and REST webservice  RSS feed

 
Yogesh Gandhi
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Hope you all are doing good...

I am stuck at a very basic but surprising question...

I have created a POJO class...and overrode the toString method by the default implementation that string gives me...



Now if i create a list of these objects and pass this to sysout....it gives me the following output;;;


OUTPUT:

[MileStoneDTO [mileStoneId=1, orderStageId=1, orderMileStoneName=ABC, orderMileStoneDate=Wed Dec 16 09:52:32 IST 2015, orderMileStoneSourceSystem=OHS, orderMileStoneEndDate=Wed Dec 16 09:52:32 IST 2015], MileStoneDTO [mileStoneId=2, orderStageId=2, orderMileStoneName=DEF, orderMileStoneDate=Wed Dec 16 09:52:32 IST 2015, orderMileStoneSourceSystem=OHS, orderMileStoneEndDate=Wed Dec 16 09:52:32 IST 2015]]


The thing to note here is the string marked in red above..

Now, if I make a spring controller and return the same list from it...and see it in a browser, the output misses the thing that was marked in red above. I presumed, it'll use a toString method of the object always...





OUTPUT:
[{"mileStoneId":1,"orderStageId":1,"orderMileStoneName":"ABC","orderMileStoneDate":1450239474577,"orderMileStoneSourceSystem":"OHS","orderMileStoneEndDate":1450239474577},{"mileStoneId":2,"orderStageId":2,"orderMileStoneName":"DEF","orderMileStoneDate":1450239474577,"orderMileStoneSourceSystem":"OHS","orderMileStoneEndDate":1450239474577}]



Can you notice?

Did it not use the toString method?
The name of the class is not coming while it is returned by controller....
Also you can see the values of dates are coming in milliseconds, where as in the earlier part it was in local timezone.

I hope I am able to put my query clearly and make you guys understand, what I am trying to ask...

Can you please help me understanding, what's going in here?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's being converted to JSON. Note that the format is not at all the same as your toString() method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!