0

My object is info

info Date: "" ids: Array[1] __proto__: Object It has all the values and I send it in angular. On the java side if the input parameter is like

public ResponseEntity<Boolean> update(@RequestBody myObject input) {...}

I get an error: 400 (Bad Request) HTTP Status 400 - type Status report message description The request sent by the client was syntactically incorrect.

But if in the api I do

public ResponseEntity<Boolean> update(@RequestBody String input) {...}

It works fine! what is wrong with it? myObject does have only

String Date;
String[] ids;
Sara
  • 2,308
  • 11
  • 50
  • 76
  • 1
    As Ian mentioned you have to deserialize the JSON string into an Object. Here's a post that covers a few options for doing this: http://stackoverflow.com/questions/1395551/convert-a-json-string-to-object-in-java – rob Feb 27 '14 at 00:01

1 Answers1

0

I'm assuming you're sending data from AngularJS using $http.post or $http.put? Angular sends JSON as a string in the request body. I would suggest you decode the JSON into a Java object using a library like Gson (see deserialization).

Ian Walter
  • 882
  • 2
  • 8
  • 23
  • Thanks Is there a way to send an object from angular? I remembered I did it before using .map something like this – Sara Feb 26 '14 at 22:24
  • Not in the way you are probably thinking. Angular sends data to the server via HTTP. The request body is composed of text. – Ian Walter Feb 26 '14 at 22:53