• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Whole Response converted to JSON

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this issue where I coded a controller and i returning a Response (endpoint consumes and produces json) as follows:



when i return something, controller is converting the whole response into json, i know is logical, but i have the same controller in another old project and as it is it works, i mean the controller returns the http status and only the json i'm returning

This is the code of one return



If test the endpoint through postman, it returns a huge json and just one child of the json, the entity is what i need to return, so what am i doing wrong...

This is the old controller that is currently working fine (i know there are a whole different libraries like swagger and version that behaves different)



 
Bartender
Posts: 1108
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may depend upon what's on the runtime classpath, since I recall the OXM [un]marshals depending upon whats been plugged in.  Could be wrong both worth checking.

I never look to fix code, prefer to offer advice and let you fix it yourself ;-)
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you guessed, it's because they're two different frameworks.
The one you are having trouble with should be returning just the object you need, not that Response object.
 
Ricardo Coto
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter Rooke I don't get what you said, you said 'depend upon what's on the runtime classpath' ? by runtime you mean the application server ? do you mean the library classpath of the project, have no idea what you're talking about...

Dave Tolls, yes thanks, that's what i did, i changed it to return a string, and to modify the http status i injected HttpServletResponse and then modify the status from there, thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic