java - spring 4 controller @RequestBody parameter -


i have following situation

public class mycustomform {   private mycustomtype a;   private mycustomtype b; }  @restcontroller public class acontroller {   @requestmapping(...)   public void mymethod(@requestbody mycustomform form){     ...   } } 

i want send in post request necessary data fill form. problem mycustomtype complex data type , cannot deserialized json.

the first thing tried write propertyeditor spring know how make deserialization string. solution works if use else beside @requestbody (it works @pathvariable example).

i made research , reason why @requestbody not working because annotation generates proxy uses own deserialization rules. rules not interfere custom propertyeditors.

the next thing tried use custom converter. solution still didn't solved issue.

any other ideas?

i understood newest version of jackson (version 2) know custom converters or propertyeditors updating jackson mapper not solution in case.

you can use @jsondeserialize mycustomtype classes like

public class mycustomform {   @jsondeserialize(using = mycustomtypedeserializer.class)   private mycustomtype a;   @jsondeserialize(using = mycustomtypedeserializer.class)   private mycustomtype b; } 

some references:

https://fasterxml.github.io/jackson-databind/javadoc/2.3.0/com/fasterxml/jackson/databind/annotation/jsondeserialize.html

http://www.davismol.net/2015/06/05/jackson-using-jsonserialize-or-jsondeserialize-annotation-to-register-a-custom-serializer-or-deserializer/

http://www.baeldung.com/jackson-custom-serialization


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -