Thanks Tatu for the suggestion. I followed your advice and tried using the
jackson's object mapper explicitly to deserialize the json String , outside
of jersey
The following is the json string
{"code":"BN2","name":"proctor and gamble","description":"PG retailer
record","retailerGroup":null,"supportedCurrencies":[],"retailerCountries":[{"country":{"code":"US","name":"United
States","vat":0.0,"includeTaxInDisplay":false,"currencies":[{"code":"USD","symbol":"$","name":"US
Dollar"}]},"defaultCurrency":{"code":"USD","symbol":"$","name":"US
Dollar"},"opticsApplied":true,"languages":{"en":"ACTIVE"},"state":"ACTIVE","supportedCurrencies":{"USD":"ACTIVE"},"retailerCountries":[{"type":"SUPPORT","details":{"TEL":"1-800-xxx-xxxx","URL":"
http://go.nook.com/support"}},{"type":"HOMEPAGE","details":{"Nook.com":"
http://go.nook.com"}},{"type":"BOOKMARK","details":{"Registration":"
http://go.nook.com/registration","Nook Blog":"
http://go.nook.com/qwk
","Facebook":"
http://go.nook.com/facebook","YouTube":"
http://go.nook.com/youtube","Getting Started":"
http://go.nook.com/qwk
","Twitter":"
http://go.nook.com/twitter
"}}],"supportGiftCard":false}],"state":"ACTIVE"}
Here SupportedCurrencies is an inner static class and we are passing an
empty array of supported currencies in the json string. I used the
following code
public class TestJson {
public static void main(String args[]) throws IOException,
JsonParseException {
ObjectMapper objMapper = new ObjectMapper();
Retailer retailer = objMapper.readValue((new FileInputStream(new
File("/Users/skoneru/Documents/retailers/bn2_retailer.txt"))),Retailer.class)
;
}
I get the following exception
Exception in thread "main" org.codehaus.jackson.map.JsonMappingException:
Can not deserialize instance of
com.bn.cloud.pm.data.vo.catalog.retl.Retailer$SupportedCurrencies out of
START_ARRAY token
at [Source: java.io.FileInputStream_at_424ecfdd; line: 1, column: 96]
(through reference chain:
com.bn.cloud.pm.data.vo.catalog.retl.Retailer["supportedCurrencies"])
at
org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
at
org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
at
org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromArray(BeanDeserializer.java:869)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:597)
at
org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
at
org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at
org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2723)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1900)
at com.bn.cloud.pm.rest.resource.TestJson.main(TestJson.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
On Thu, Jun 28, 2012 at 11:02 AM, Tatu Saloranta <tsaloranta_at_gmail.com>wrote:
> On Thu, Jun 28, 2012 at 10:16 AM, suchitha koneru
> <suchi.koneru_at_gmail.com> wrote:
> > Thanks Tatu for the response. I have inner classes , can this be a
> issue
> > for derserialization as stated in the
> > JIRA http://jira.codehaus.org/browse/JACKSON-594.
> >
> > The class Retailer and its Data member RetailerCountries both have a
> > static inner class of same name" Supported Currencies" but with
> different
> > definitions.
> >
> > can this be a problem ?
>
> I don't think so, since your inner classes are static as expected.
> [JACKSON-594] was implemented for 1.9 as well; and if it was causing
> the failure you would see different exception.
>
> If you can write a stand-alone test (outside of Jersey), I might be
> able to help figuring out what exacty is happening.
>
> -+ Tatu +-
>