1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.adservices.data.customaudience; 18 19 import android.adservices.common.AdData; 20 21 import androidx.annotation.NonNull; 22 23 import com.android.adservices.data.common.DBAdData; 24 25 import org.json.JSONException; 26 import org.json.JSONObject; 27 28 /** Strategy for converting to and from an AdData object in different parts of the code */ 29 public interface AdDataConversionStrategy { 30 /** 31 * Serialize {@link DBAdData} to {@link JSONObject}. 32 * 33 * @param adData the {@link DBAdData} object to serialize 34 * @return the json serialization of the AdData object 35 */ toJson(DBAdData adData)36 JSONObject toJson(DBAdData adData) throws JSONException; 37 38 /** 39 * Deserialize {@link DBAdData} to {@link JSONObject}. 40 * 41 * @param json the {@link JSONObject} object to dwserialize 42 * @return the {@link DBAdData} deserialized from the json 43 */ fromJson(JSONObject json)44 DBAdData.Builder fromJson(JSONObject json) throws JSONException; 45 46 /** 47 * Parse parcelable {@link AdData} to storage model {@link DBAdData}. 48 * 49 * @param parcelable the service model. 50 * @return storage model 51 */ 52 @NonNull fromServiceObject(@onNull AdData parcelable)53 DBAdData.Builder fromServiceObject(@NonNull AdData parcelable); 54 } 55