Announcement Announcement Module
Collapse
No announcement yet.
JSON controllers should return 400 when fail to parse JSON payload Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSON controllers should return 400 when fail to parse JSON payload

    Hi,

    I have a JSON controller and when I pass it invalid (unparseable) JSON it produces a status code of 200 and HTML output from the uncaughtException.jspx. Specifically the exception raised is flexjson.JSONException and I include an excerpt of the stack trace below.

    Code:
    flexjson.JSONException: [ destination.id ]:  Can not convert java.lang.String into java.lang.Long
    	at flexjson.ObjectBinder.cannotConvertValueToTargetType(ObjectBinder.java:162)
    	at flexjson.factories.LongObjectFactory.instantiate(LongObjectFactory.java:16)
    	at flexjson.ObjectBinder.bind(ObjectBinder.java:86)
    	at flexjson.ObjectBinder.bindIntoObject(ObjectBinder.java:139)
    	at flexjson.factories.BeanObjectFactory.instantiate(BeanObjectFactory.java:17)
    	at flexjson.ObjectBinder.bind(ObjectBinder.java:86)
    	at flexjson.ObjectBinder.bindIntoObject(ObjectBinder.java:139)
    	at flexjson.factories.ClassLocatorObjectFactory.instantiate(ClassLocatorObjectFactory.java:38)
    	at flexjson.ObjectBinder.bind(ObjectBinder.java:86)
    	at flexjson.ObjectBinder.bind(ObjectBinder.java:65)
    	at flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:158)
    	at com.trakeo.mb.model.Consignment.fromJson_aroundBody2(Consignment.java:127)
    I suggest that an unparseable JSON payload should result in 400 - BAD REQUEST. Do you think this is a suitable issue to report in JIRA?

    Finally, it looks like WebJsonMetadata.getCreateFromJsonMethod in the web mvc addon is the place to detect the JSONException and return the 400 response. Does anyone have other suggestions?

    Thanks in advance,
    Tim
Working...
X