• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

deserializing json into java object in spring having a superclass reference to hold a subclass inst.  RSS feed

 
Ranch Hand
Posts: 42
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I am using JDK 1.6 and Spring 3.1.3 to create a RESTful service that accepts an object as JSON which gets converted into a Java object by Spring that I have specified in my service method. Now Spring takes care of parsing the JSON into the Java object and everything works fine.

The problem appears when I add a property to my primary object which is a superclass reference and can hold a reference to one of its many subclasses. When the JSON is received, the data for the superclass reference is equivalent to one of the subclasses. I found this link that talks about writing a custom deserializer (http://stackoverflow.com/questions/16872492/gson-and-abstract-superclasses-deserialization-issue) but I dont understand how to configure spring to use this.

Any pointers?

Regards
Dinkar
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using GSON right now? Can you post your Spring configuration?
 
Dinkar Chaturvedi
Ranch Hand
Posts: 42
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes we are using GSON. However, I believe Spring internally uses Jackson for all its JSON conversion needs (though I maybe wrong).

Spring configuration might be overwhelming because we have more than 20 modules as part of the build. What exactly are you looking for?

Regards
Dinkar
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!