0

I want to create a custom json response for a new Java Spring Boot application. At the moment I just want to create a dummy json object -- to start controlling the structure of the output json response.

When I do this it wants to create cast prefixes to the .puts -- I used to use Mongodb -- BasicDBObject -- but now I've not got mongo here.

 DBObject obj = new BasicDBObject();
 obj.put( "foo", "bar" );

what do I do instead?

--

@RequestMapping(value = "/login", method = RequestMethod.GET)
@CrossOrigin(origins = {"*"})
public ResponseEntity<?> login(
        @RequestParam(value="email", required=false, defaultValue="email") String email,
        @RequestParam(value="password", required=false, defaultValue="password") String password, 
        HttpServletRequest request
        ) throws  Exception {

                Object response = new Object();
                    response.put("information", "test");
                    response.put("id", 3);
                    response.put("name", "course1");

                return new ResponseEntity<>(response, HttpStatus.OK);
        }
The Old County
  • 89
  • 13
  • 59
  • 129

1 Answers1

-2
**@ResetController**   // add this
public class YourClass{

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    @CrossOrigin(origins = {"*"})
    public ResponseEntity<?> login(){
        Object response = new Object();
                    response.put("information", "test");
                    response.put("id", 3);
                    response.put("name", "course1");

        return new ResponseEntity<>(response, HttpStatus.OK);
     }
}
Komal12
  • 3,340
  • 4
  • 16
  • 25
  • You mean "@RestController" -- it says its disallowed at this location. – The Old County Sep 05 '17 at 01:35
  • I have installed the dependency com.googlecode.json-simple json-simple -- to get it working with JSONObject response = new JSONObject(); response.put("name", "mkyong.com"); response.put("age", new Integer(100)); – The Old County Sep 05 '17 at 01:47