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

com.stripe.model.FeeRefundCollectionDeserializer Maven / Gradle / Ivy

There is a newer version: 28.2.0
Show newest version
package com.stripe.model;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import com.stripe.model.ExpandableField;
import com.stripe.model.ExpandableFieldDeserializer;

import java.lang.reflect.Type;
import java.util.List;

public class FeeRefundCollectionDeserializer implements JsonDeserializer {

	public static final Type REFUND_LIST_TYPE = new TypeToken>() {
	}.getType();

	public FeeRefundCollection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
			throws JsonParseException {
		Gson gson = new GsonBuilder()
				.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
				.registerTypeAdapter(ExpandableField.class, new ExpandableFieldDeserializer())
				.create();

		// API versions 2014-07-26 and earlier render application fee refunds as an array instead of an object
		if (json.isJsonArray()) {
			List refunds = gson.fromJson(json, REFUND_LIST_TYPE);
			FeeRefundCollection collection = new FeeRefundCollection();
			collection.setData(refunds);
			collection.setHasMore(false);
			collection.setTotalCount(refunds.size());
			return collection;
		} else {
			return gson.fromJson(json, typeOfT);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy