Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getAsText() not called Spring MVC PropertyEditorSupport AJAX

 
Juggy Obhi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a enum property editor like:


I have registered it in my Spring MVC controller like:


Whenever i make an AJAX call to this controller the setAsText() method gets called and works fine. The problem is with getAsText() method which is not getting called when the server responds with a JSON string.

Please guide. What am i missing?


Regards,
Jagpreet Singh
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not knowing for sure. My guess would be that PropertyEditors in Spring are mainly if only used to convert String to some format. But not the other way around. So I think the incoming String is being converted to the type, but it won't try to use the PropertyEditor on the way out. For that I would think you need to use a Convertor in Jackson. Meaning I think it is Jackson that doesn't try to convert it from a string. Not Spring at all.

Just a guess, but try making a Jackson converter.

Something like this

https://github.com/aws/aws-sdk-java/blob/master/src/main/java/com/amazonaws/services/simpleworkflow/flow/JsonDataConverter.java

Actually, looking at some code I had I think I mean a Serializer not a converter in Jackson

JsonSerializer

Mark
 
Juggy Obhi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Mark. Words of wisdom. big help


Regards,
Jagpreet Singh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic