I have an html/jsp form that I am serializing(using jquery) and passing to a sp开发者_JS百科ring controller via ajax. In fact it is a spring-mvc form that is bound to an attribute.
My first question is: as I am passing the data from the form via ajax this binding is not relevant ?
Secondly, the object it is bound to is quite a complex hibernate entity object and I am experiencing problems converting the json to an instance of the object - it has references to other objects etc etc, well actually I am not sure what the exact problems are as the error message is not particularly clear: Content type 'application/json' not supported.
Should I use a DTO/value object instead of the entity object, and then create an entity object based on the DTO?
Or, should I track down the problem fields in the entity object/form that are causing the json conversion to fail , this will be time-consuming and dull, but the end result seems to me to be neater.
Suggestions welcome.
edit: Conversion of simple forms/objects is working fine when they just have a couple of string properties and related getters/setters. The controller and javascript code.
Yes, use a DTO. Apart from avoiding the various ORM issues that you're experiencing, it will make it much easier for you to define what you do and do not want your users to be able to change. For example, what if someone sent you a hacked JSON object that defines a property or relationship that you didn't want them to be able to modify? How prepared are you to perform (and maintain) checks on every property on that model object to avoid such hacks?
精彩评论