com.facebook.ads.sdk.FlexibleTargeting Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of facebook-java-business-sdk Show documentation
Show all versions of facebook-java-business-sdk Show documentation
Facebook Business Solutions SDK for Java
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.ads.sdk;
import java.io.File;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Function;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.facebook.ads.sdk.APIException.MalformedResponseException;
/**
* This class is auto-generated.
*
* For any issues or feature requests related to this class, please let us know
* on github and we'll fix in our codegen framework. We'll not be able to accept
* pull request for this class.
*
*/
public class FlexibleTargeting extends APINode {
@SerializedName("behaviors")
private List mBehaviors = null;
@SerializedName("college_years")
private List mCollegeYears = null;
@SerializedName("connections")
private List mConnections = null;
@SerializedName("custom_audiences")
private List mCustomAudiences = null;
@SerializedName("education_majors")
private List mEducationMajors = null;
@SerializedName("education_schools")
private List mEducationSchools = null;
@SerializedName("education_statuses")
private List mEducationStatuses = null;
@SerializedName("ethnic_affinity")
private List mEthnicAffinity = null;
@SerializedName("family_statuses")
private List mFamilyStatuses = null;
@SerializedName("friends_of_connections")
private List mFriendsOfConnections = null;
@SerializedName("generation")
private List mGeneration = null;
@SerializedName("home_ownership")
private List mHomeOwnership = null;
@SerializedName("home_type")
private List mHomeType = null;
@SerializedName("home_value")
private List mHomeValue = null;
@SerializedName("household_composition")
private List mHouseholdComposition = null;
@SerializedName("income")
private List mIncome = null;
@SerializedName("industries")
private List mIndustries = null;
@SerializedName("interested_in")
private List mInterestedIn = null;
@SerializedName("interests")
private List mInterests = null;
@SerializedName("life_events")
private List mLifeEvents = null;
@SerializedName("moms")
private List mMoms = null;
@SerializedName("net_worth")
private List mNetWorth = null;
@SerializedName("office_type")
private List mOfficeType = null;
@SerializedName("politics")
private List mPolitics = null;
@SerializedName("relationship_statuses")
private List mRelationshipStatuses = null;
@SerializedName("user_adclusters")
private List mUserAdclusters = null;
@SerializedName("work_employers")
private List mWorkEmployers = null;
@SerializedName("work_positions")
private List mWorkPositions = null;
protected static Gson gson = null;
public FlexibleTargeting() {
}
public String getId() {
return null;
}
public static FlexibleTargeting loadJSON(String json, APIContext context, String header) {
FlexibleTargeting flexibleTargeting = getGson().fromJson(json, FlexibleTargeting.class);
if (context.isDebug()) {
JsonParser parser = new JsonParser();
JsonElement o1 = parser.parse(json);
JsonElement o2 = parser.parse(flexibleTargeting.toString());
if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
}
if (!o1.equals(o2)) {
context.log("[Warning] When parsing response, object is not consistent with JSON:");
context.log("[JSON]" + o1);
context.log("[Object]" + o2);
}
}
flexibleTargeting.context = context;
flexibleTargeting.rawValue = json;
flexibleTargeting.header = header;
return flexibleTargeting;
}
public static APINodeList parseResponse(String json, APIContext context, APIRequest request, String header) throws MalformedResponseException {
APINodeList flexibleTargetings = new APINodeList(request, json, header);
JsonArray arr;
JsonObject obj;
JsonParser parser = new JsonParser();
Exception exception = null;
try{
JsonElement result = parser.parse(json);
if (result.isJsonArray()) {
// First, check if it's a pure JSON Array
arr = result.getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
flexibleTargetings.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context, header));
};
return flexibleTargetings;
} else if (result.isJsonObject()) {
obj = result.getAsJsonObject();
if (obj.has("data")) {
if (obj.has("paging")) {
JsonObject paging = obj.get("paging").getAsJsonObject();
if (paging.has("cursors")) {
JsonObject cursors = paging.get("cursors").getAsJsonObject();
String before = cursors.has("before") ? cursors.get("before").getAsString() : null;
String after = cursors.has("after") ? cursors.get("after").getAsString() : null;
flexibleTargetings.setCursors(before, after);
}
String previous = paging.has("previous") ? paging.get("previous").getAsString() : null;
String next = paging.has("next") ? paging.get("next").getAsString() : null;
flexibleTargetings.setPaging(previous, next);
if (context.hasAppSecret()) {
flexibleTargetings.setAppSecret(context.getAppSecretProof());
}
}
if (obj.get("data").isJsonArray()) {
// Second, check if it's a JSON array with "data"
arr = obj.get("data").getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
flexibleTargetings.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context, header));
};
} else if (obj.get("data").isJsonObject()) {
// Third, check if it's a JSON object with "data"
obj = obj.get("data").getAsJsonObject();
boolean isRedownload = false;
for (String s : new String[]{"campaigns", "adsets", "ads"}) {
if (obj.has(s)) {
isRedownload = true;
obj = obj.getAsJsonObject(s);
for (Map.Entry entry : obj.entrySet()) {
flexibleTargetings.add(loadJSON(entry.getValue().toString(), context, header));
}
break;
}
}
if (!isRedownload) {
flexibleTargetings.add(loadJSON(obj.toString(), context, header));
}
}
return flexibleTargetings;
} else if (obj.has("images")) {
// Fourth, check if it's a map of image objects
obj = obj.get("images").getAsJsonObject();
for (Map.Entry entry : obj.entrySet()) {
flexibleTargetings.add(loadJSON(entry.getValue().toString(), context, header));
}
return flexibleTargetings;
} else {
// Fifth, check if it's an array of objects indexed by id
boolean isIdIndexedArray = true;
for (Map.Entry entry : obj.entrySet()) {
String key = (String) entry.getKey();
if (key.equals("__fb_trace_id__")) {
continue;
}
JsonElement value = (JsonElement) entry.getValue();
if (
value != null &&
value.isJsonObject() &&
value.getAsJsonObject().has("id") &&
value.getAsJsonObject().get("id") != null &&
value.getAsJsonObject().get("id").getAsString().equals(key)
) {
flexibleTargetings.add(loadJSON(value.toString(), context, header));
} else {
isIdIndexedArray = false;
break;
}
}
if (isIdIndexedArray) {
return flexibleTargetings;
}
// Sixth, check if it's pure JsonObject
flexibleTargetings.clear();
flexibleTargetings.add(loadJSON(json, context, header));
return flexibleTargetings;
}
}
} catch (Exception e) {
exception = e;
}
throw new MalformedResponseException(
"Invalid response string: " + json,
exception
);
}
@Override
public APIContext getContext() {
return context;
}
@Override
public void setContext(APIContext context) {
this.context = context;
}
@Override
public String toString() {
return getGson().toJson(this);
}
public List getFieldBehaviors() {
return mBehaviors;
}
public FlexibleTargeting setFieldBehaviors(List value) {
this.mBehaviors = value;
return this;
}
public FlexibleTargeting setFieldBehaviors(String value) {
Type type = new TypeToken>(){}.getType();
this.mBehaviors = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldCollegeYears() {
return mCollegeYears;
}
public FlexibleTargeting setFieldCollegeYears(List value) {
this.mCollegeYears = value;
return this;
}
public List getFieldConnections() {
return mConnections;
}
public FlexibleTargeting setFieldConnections(List value) {
this.mConnections = value;
return this;
}
public FlexibleTargeting setFieldConnections(String value) {
Type type = new TypeToken>(){}.getType();
this.mConnections = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldCustomAudiences() {
return mCustomAudiences;
}
public FlexibleTargeting setFieldCustomAudiences(List value) {
this.mCustomAudiences = value;
return this;
}
public FlexibleTargeting setFieldCustomAudiences(String value) {
Type type = new TypeToken>(){}.getType();
this.mCustomAudiences = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldEducationMajors() {
return mEducationMajors;
}
public FlexibleTargeting setFieldEducationMajors(List value) {
this.mEducationMajors = value;
return this;
}
public FlexibleTargeting setFieldEducationMajors(String value) {
Type type = new TypeToken>(){}.getType();
this.mEducationMajors = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldEducationSchools() {
return mEducationSchools;
}
public FlexibleTargeting setFieldEducationSchools(List value) {
this.mEducationSchools = value;
return this;
}
public FlexibleTargeting setFieldEducationSchools(String value) {
Type type = new TypeToken>(){}.getType();
this.mEducationSchools = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldEducationStatuses() {
return mEducationStatuses;
}
public FlexibleTargeting setFieldEducationStatuses(List value) {
this.mEducationStatuses = value;
return this;
}
public List getFieldEthnicAffinity() {
return mEthnicAffinity;
}
public FlexibleTargeting setFieldEthnicAffinity(List value) {
this.mEthnicAffinity = value;
return this;
}
public FlexibleTargeting setFieldEthnicAffinity(String value) {
Type type = new TypeToken>(){}.getType();
this.mEthnicAffinity = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldFamilyStatuses() {
return mFamilyStatuses;
}
public FlexibleTargeting setFieldFamilyStatuses(List value) {
this.mFamilyStatuses = value;
return this;
}
public FlexibleTargeting setFieldFamilyStatuses(String value) {
Type type = new TypeToken>(){}.getType();
this.mFamilyStatuses = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldFriendsOfConnections() {
return mFriendsOfConnections;
}
public FlexibleTargeting setFieldFriendsOfConnections(List value) {
this.mFriendsOfConnections = value;
return this;
}
public FlexibleTargeting setFieldFriendsOfConnections(String value) {
Type type = new TypeToken>(){}.getType();
this.mFriendsOfConnections = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldGeneration() {
return mGeneration;
}
public FlexibleTargeting setFieldGeneration(List value) {
this.mGeneration = value;
return this;
}
public FlexibleTargeting setFieldGeneration(String value) {
Type type = new TypeToken>(){}.getType();
this.mGeneration = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldHomeOwnership() {
return mHomeOwnership;
}
public FlexibleTargeting setFieldHomeOwnership(List value) {
this.mHomeOwnership = value;
return this;
}
public FlexibleTargeting setFieldHomeOwnership(String value) {
Type type = new TypeToken>(){}.getType();
this.mHomeOwnership = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldHomeType() {
return mHomeType;
}
public FlexibleTargeting setFieldHomeType(List value) {
this.mHomeType = value;
return this;
}
public FlexibleTargeting setFieldHomeType(String value) {
Type type = new TypeToken>(){}.getType();
this.mHomeType = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldHomeValue() {
return mHomeValue;
}
public FlexibleTargeting setFieldHomeValue(List value) {
this.mHomeValue = value;
return this;
}
public FlexibleTargeting setFieldHomeValue(String value) {
Type type = new TypeToken>(){}.getType();
this.mHomeValue = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldHouseholdComposition() {
return mHouseholdComposition;
}
public FlexibleTargeting setFieldHouseholdComposition(List value) {
this.mHouseholdComposition = value;
return this;
}
public FlexibleTargeting setFieldHouseholdComposition(String value) {
Type type = new TypeToken>(){}.getType();
this.mHouseholdComposition = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldIncome() {
return mIncome;
}
public FlexibleTargeting setFieldIncome(List value) {
this.mIncome = value;
return this;
}
public FlexibleTargeting setFieldIncome(String value) {
Type type = new TypeToken>(){}.getType();
this.mIncome = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldIndustries() {
return mIndustries;
}
public FlexibleTargeting setFieldIndustries(List value) {
this.mIndustries = value;
return this;
}
public FlexibleTargeting setFieldIndustries(String value) {
Type type = new TypeToken>(){}.getType();
this.mIndustries = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldInterestedIn() {
return mInterestedIn;
}
public FlexibleTargeting setFieldInterestedIn(List value) {
this.mInterestedIn = value;
return this;
}
public List getFieldInterests() {
return mInterests;
}
public FlexibleTargeting setFieldInterests(List value) {
this.mInterests = value;
return this;
}
public FlexibleTargeting setFieldInterests(String value) {
Type type = new TypeToken>(){}.getType();
this.mInterests = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldLifeEvents() {
return mLifeEvents;
}
public FlexibleTargeting setFieldLifeEvents(List value) {
this.mLifeEvents = value;
return this;
}
public FlexibleTargeting setFieldLifeEvents(String value) {
Type type = new TypeToken>(){}.getType();
this.mLifeEvents = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldMoms() {
return mMoms;
}
public FlexibleTargeting setFieldMoms(List value) {
this.mMoms = value;
return this;
}
public FlexibleTargeting setFieldMoms(String value) {
Type type = new TypeToken>(){}.getType();
this.mMoms = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldNetWorth() {
return mNetWorth;
}
public FlexibleTargeting setFieldNetWorth(List value) {
this.mNetWorth = value;
return this;
}
public FlexibleTargeting setFieldNetWorth(String value) {
Type type = new TypeToken>(){}.getType();
this.mNetWorth = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldOfficeType() {
return mOfficeType;
}
public FlexibleTargeting setFieldOfficeType(List value) {
this.mOfficeType = value;
return this;
}
public FlexibleTargeting setFieldOfficeType(String value) {
Type type = new TypeToken>(){}.getType();
this.mOfficeType = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldPolitics() {
return mPolitics;
}
public FlexibleTargeting setFieldPolitics(List value) {
this.mPolitics = value;
return this;
}
public FlexibleTargeting setFieldPolitics(String value) {
Type type = new TypeToken>(){}.getType();
this.mPolitics = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldRelationshipStatuses() {
return mRelationshipStatuses;
}
public FlexibleTargeting setFieldRelationshipStatuses(List value) {
this.mRelationshipStatuses = value;
return this;
}
public List getFieldUserAdclusters() {
return mUserAdclusters;
}
public FlexibleTargeting setFieldUserAdclusters(List value) {
this.mUserAdclusters = value;
return this;
}
public FlexibleTargeting setFieldUserAdclusters(String value) {
Type type = new TypeToken>(){}.getType();
this.mUserAdclusters = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldWorkEmployers() {
return mWorkEmployers;
}
public FlexibleTargeting setFieldWorkEmployers(List value) {
this.mWorkEmployers = value;
return this;
}
public FlexibleTargeting setFieldWorkEmployers(String value) {
Type type = new TypeToken>(){}.getType();
this.mWorkEmployers = IDName.getGson().fromJson(value, type);
return this;
}
public List getFieldWorkPositions() {
return mWorkPositions;
}
public FlexibleTargeting setFieldWorkPositions(List value) {
this.mWorkPositions = value;
return this;
}
public FlexibleTargeting setFieldWorkPositions(String value) {
Type type = new TypeToken>(){}.getType();
this.mWorkPositions = IDName.getGson().fromJson(value, type);
return this;
}
synchronized /*package*/ static Gson getGson() {
if (gson != null) {
return gson;
} else {
gson = new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.STATIC)
.excludeFieldsWithModifiers(Modifier.PROTECTED)
.disableHtmlEscaping()
.create();
}
return gson;
}
public FlexibleTargeting copyFrom(FlexibleTargeting instance) {
this.mBehaviors = instance.mBehaviors;
this.mCollegeYears = instance.mCollegeYears;
this.mConnections = instance.mConnections;
this.mCustomAudiences = instance.mCustomAudiences;
this.mEducationMajors = instance.mEducationMajors;
this.mEducationSchools = instance.mEducationSchools;
this.mEducationStatuses = instance.mEducationStatuses;
this.mEthnicAffinity = instance.mEthnicAffinity;
this.mFamilyStatuses = instance.mFamilyStatuses;
this.mFriendsOfConnections = instance.mFriendsOfConnections;
this.mGeneration = instance.mGeneration;
this.mHomeOwnership = instance.mHomeOwnership;
this.mHomeType = instance.mHomeType;
this.mHomeValue = instance.mHomeValue;
this.mHouseholdComposition = instance.mHouseholdComposition;
this.mIncome = instance.mIncome;
this.mIndustries = instance.mIndustries;
this.mInterestedIn = instance.mInterestedIn;
this.mInterests = instance.mInterests;
this.mLifeEvents = instance.mLifeEvents;
this.mMoms = instance.mMoms;
this.mNetWorth = instance.mNetWorth;
this.mOfficeType = instance.mOfficeType;
this.mPolitics = instance.mPolitics;
this.mRelationshipStatuses = instance.mRelationshipStatuses;
this.mUserAdclusters = instance.mUserAdclusters;
this.mWorkEmployers = instance.mWorkEmployers;
this.mWorkPositions = instance.mWorkPositions;
this.context = instance.context;
this.rawValue = instance.rawValue;
return this;
}
public static APIRequest.ResponseParser getParser() {
return new APIRequest.ResponseParser() {
public APINodeList parseResponse(String response, APIContext context, APIRequest request, String header) throws MalformedResponseException {
return FlexibleTargeting.parseResponse(response, context, request, header);
}
};
}
}