Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

erek
Regular Visitor

Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

Sample codes not working for card services.   Issue seems to be with JSON Arrays being passed into the Java Classes for conversion.   All tests end up failing in the sample codes for Card Services API:

 

"com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions out of START_ARRAY token
at [Source: {"cardholderLowBalanceAmount": {"amount": 0, "currencyCode": "840"}, "pushID": "test", "subscriptions": [{"notificationID": "LowBalance_Email", "isSubscribed": true}, {"notificationID": "ChangeOfCardStatus_Text", "isSubscribed": true}, {"notificationID": "DailyAvailableBalance_PushNotification", "isSubscribed": true}}; line: 1, column: 105] (through reference chain: com.visa.developer.sample.card_services_api.model.NotificationSubscriptionsputPayload["subscriptions"])

at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270)
at com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1234)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1122)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1075)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromArray(BeanDeserializerBase.java:1371)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:174)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:150)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:504)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:104)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3814)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858)
at com.visa.developer.sample.card_services_api.api.CardServicesApiTest.putnotificationSubscriptionsTest(CardServicesApiTest.java:522)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

"

10 REPLIES 10
erek
Regular Visitor

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

this is for the Java code sample of the Card Services API.

 

 

CardServicesApiTest:

 

@Test
public void putnotificationSubscriptionsTest() throws IOException {

 String jsonPayload = transformPayload("{\"cardholderLowBalanceAmount\": {\"amount\": 0, \"currencyCode\": \"840\"}, \"pushID\": \"test\", \"subscriptions\": [{\"notificationID\": \"LowBalance_Email\", \"isSubscribed\": true}, {\"notificationID\": \"ChangeOfCardStatus_Text\", \"isSubscribed\": true}, {\"notificationID\": \"DailyAvailableBalance_PushNotification\", \"isSubscribed\": true}]}");

ObjectMapper mapper = new ObjectMapper();
NotificationSubscriptionsputPayload body = mapper.readValue(jsonPayload, NotificationSubscriptionsputPayload.class);

//transformPayload()
String cardId = Arrays.asList("cardId_example").get(0);
System.err.println(cardId);

NotificationSubscriptionsputResponse response = api.putnotificationSubscriptions(body, cardId);
}

 

----

//(from: NotificationSubscriptionsputPayload.class)

 

 

public NotificationSubscriptionsputPayload subscriptions(Subscriptions subscriptions) {
this.subscriptions = subscriptions;
return this;
}

 

jvenkata
Community Moderator

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

Hi,

 

Thanks for bringing this to our notice. Please let me know if you are able to fix it by updating the model classes. We will take a look and plan for a fix in future release.

 

Thanks,

Jai

erek
Regular Visitor

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

are you able to reproduce the issue on your end?

 

i'm also getting HTTP 400 Bad Request for all the other tests

erek
Regular Visitor

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

anyone?

ricardo_visa
Community Scholar

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

@erek - are you still experiencing this? Please let me know.




Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.
swaritsharma
Regular Contributor

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

I am getting the same error in Payment Account Validation API. Please help resolve this issue.

fabrizioa
Regular Visitor

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

I used to have the same issue with the MerchantBenchmarkApiTest, but looks like the same problem in the serialization process.

 

The response json looked like this

...

"response": {
"responseData": [
{
     "groupName": "standard",
     "fraudChbktoSalesGrowthYoY": "-28.0456",
     "nonfraudChbktoSalesGrowthYoY": "36.5908",
     "fraudChbktoSalesRatio": "0.4564",
     "nonfraudChbktoSalesRatio": "0.209",
     "ticketGrowthMoM": "-0.0174",
     "ticketGrowthYoY": "0.0113",
     "salesTranCntGrowthMoM": "-3.3139",
     "salesVolumeGrowthMoM": "-4.9995",
     "salesTranCntGrowthYoY": "13.809",
     "salesVolumeGrowthYoY": "15.0983"
}
  ]
}

 

To me it just worked by changing the type of Object annotated in Jackson to List<Object> in Response.java

This is because it contains an array and during the serialization returns the error.

 

OLD CODE

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonProperty("responseData")
private ResponseData responseData = null;

NEW CODE

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonProperty("responseData")
private List<ResponseData> responseData = null;

Then change all the following accessors coherently.

 

Hope this helps to solve similar issues with other TEST Api.

 

AGC
New Contributor

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

I had a similar issue with Global ATM Locator API with 74 java compilation errors on missing classes like ComplexType and with no reference, help or details on the same with sample code. And was unable to find an answer.. This answer at least helped me to resolve the compile time errors.

johnjack
Newbie

Re: Can not deserialize instance of com.visa.developer.sample.card_services_api.model.Subscriptions

are you able to reproduce the issue on your end? robux hilesi