All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.konduto.sdk.adapters.KondutoShoppingCartAdapter Maven / Gradle / Ivy

Go to download

Easily integrate with Konduto (https://konduto.com), a fraud prevention service.

There is a newer version: 2.17.4
Show newest version
package com.konduto.sdk.adapters;

import com.google.gson.*;
import com.konduto.sdk.models.KondutoItem;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by rsampaio on 11/08/14.
 *
 * Shopping cart (collection of KondutoItem), serialization/deserialization.
 *
 */
public class KondutoShoppingCartAdapter
		implements JsonSerializer>, JsonDeserializer> {


	@Override
	public Collection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
			throws JsonParseException {

		Collection shoppingCart = new ArrayList<>();

		for(JsonElement je : json.getAsJsonArray()) {
			shoppingCart.add((KondutoItem) context.deserialize(je, KondutoItem.class));
		}
		return shoppingCart;
	}

	@Override
	public JsonElement serialize(Collection shoppingCart, Type typeOfSrc, JsonSerializationContext context) {
		JsonArray json = new JsonArray();

		for(KondutoItem item : shoppingCart) {
			json.add(context.serialize(item));
		}

		return json;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy