I am implementing Google Retail Search into the project. Google API require me to provide Product object in given JSON format. JSON representation of Product with minimum number of fields populated look like following:
{
"id": "1234",
"categories": "Apparel & Accessories > Shoes",
"title": "ABC sneakers"
}
Corresponding Product object:
Product product = Product.newBuilder()
.setId("1234")
.addCategories("Apparel & Accessories > Shoes")
.setTitle("ABC sneakers")
.build();
When I try to parse the Product object to JSON using Gson library I receive following result:
{
"expirationCase_": 0,
"name_": "",
"id_": "1234",
"type_": 0,
"primaryProductId_": "",
"collectionMemberIds_": [],
"gtin_": "",
"categories_": [
"Apparel & Accessories > Shoes"
],
"title_": "ABC sneakers",
"brands_": [],
"description_": "",
"languageCode_": "",
"tags_": [],
"availability_": 0,
"fulfillmentInfo_": [],
"uri_": "",
"images_": [],
"sizes_": [],
"materials_": [],
"patterns_": [],
"conditions_": [],
"promotions_": [],
"variants_": [],
"localInventories_": [],
"memoizedIsInitialized": 1,
"unknownFields": {
"fields": {}
},
"memoizedSize": -1,
"memoizedHashCode": 0
}
How can I parse com.google.cloud.retail.v2.Product objects to its correct JSON representation? Is there any Google provided solution or should I create my own Product?
I feel helpless on that.
I tried to use following Gson for parsing and have no idea what can I change here.
Gson gson2 = new GsonBuilder().disableHtmlEscaping().create();