2

I receive a JSON string as an input which I need to convert to an object of Product class. The Product class belongs to google client library 1.19.1.

When converting JSON String to a Product object, using object mapper, it gives following error.

Error :

Exception in thread "main" java.lang.IllegalArgumentException: Can not set com.google.api.services.content.model.Price field com.google.api.services.content.model.Product.price to java.util.LinkedHashMap

Can any one please suggest, how to convert the input json string

Code for the same is written below :

import org.codehaus.jackson.map.ObjectMapper;

String temp = "{\"channel\":\"online\",\"contentLanguage\":\"en\",\"offerId\":\"towel\",\"targetCountry\":\"IN\",\"condition\":\"refurbished\",\"link\":\"https://www.sokrati.com\",\"price\":{\"value\":\"12\",\"currency\":\"INR\"},\"title\":\"Adventures of Tintin\",\"availability\":\"preorder\"}";

Product product = mapper.readValue(temp, Product.class);

1 Answers1

0

I managed to do this with com.google.api.client.json.jackson2.JacksonFactory class:

com.google.api.client.json.jackson2.JacksonFactory().fromString(temp, com.google.api.services.content.model.Product.class)