androidjsonazure-mobile-servicesazure-android-sdkgson

java.lang.IllegalStateException: Not a JSON Object: [] on Azure operation


I am using Azure Mobile Application to insert my new User during registration ,

Then it throws an exception with the message : java.lang.IllegalStateException: Not a JSON Object: []

(I have no entity in the Users table)

my codes :

public static void registerUserToTheDataBase(final User user){
    AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            try {
                UserManager.user = mUserManager.insert(user).get();
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }
    };
    AsyncTaskController.runAsyncTask(asyncTask);
}

I have checked all my Database Attributes's name are correct

and this is my User object

public class User implements Serializable {
@com.google.gson.annotations.SerializedName("id")
private String id;
@com.google.gson.annotations.SerializedName("name")
private String name;
@com.google.gson.annotations.SerializedName("live")
private String live;
@com.google.gson.annotations.SerializedName("age")
private int age;
@com.google.gson.annotations.SerializedName("password")
private String password;
@com.google.gson.annotations.SerializedName("account")
private String account;
@com.google.gson.annotations.SerializedName("phone")
private String phone;
@com.google.gson.annotations.SerializedName("email")
private String email;
@com.google.gson.annotations.SerializedName("imageUrl")
private String imageUrl;

@com.google.gson.annotations.SerializedName("productsHistoryRecord")
private List<ProductImp> productsHistoryRecord;
@com.google.gson.annotations.SerializedName("productsSales")
private List<ProductImp> productsSales;
@com.google.gson.annotations.SerializedName("productsInCart")
private List<ProductImp> productsInCart;
@com.google.gson.annotations.SerializedName("mails")
private List<Mail> mails;


public String getImageUrl() {
    return imageUrl;
}

public void setImageUrl(String imageUrl) {
    this.imageUrl = imageUrl;
}

public String getId() {
    return id;
}

public String getName() {
    return name;
}

public int getAge() {
    return age;
}

public String getAccount() {
    return account;
}

public String getLive() {
    return live;
}

public String getPassword() {
    return password;
}

public String getPhone() {
    return phone;
}

public void setName(String name) {
    this.name = name;
}

public void setAccount(String account) {
    this.account = account;
}

public void setAge(int age) {
    this.age = age;
}

public void setLive(String live) {
    this.live = live;
}

public void setPassword(String password) {
    this.password = password;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public void setId(String id) {
    this.id = id;
}

public void setEmail(String email) {
    this.email = email;
}

public String getEmail() {
    return email;
}

public List<Mail> getMails() {
    return mails;
}

public void setMails(List<Mail> mails) {
    this.mails = mails;
}

public List<ProductImp> getProductsHistoryRecord() {
    return productsHistoryRecord;
}

public void setProductsHistoryRecord(List<ProductImp> productsHistoryRecord) {
    this.productsHistoryRecord = productsHistoryRecord;
}

public List<ProductImp> getProductsInCart() {
    return productsInCart;
}

public void setProductsInCart(List<ProductImp> productsInCart) {
    this.productsInCart = productsInCart;
}

public List<ProductImp> getProductsSales() {
    return productsSales;
}

public void setProductsSales(List<ProductImp> productsSales) {
    this.productsSales = productsSales;
}

@Override
public String toString() {
    return "user information :" + name + "," + age + "," + live + "," + phone + "," + account + "," + password
      +   ","   + productsHistoryRecord + "," + productsInCart + "," +  productsSales ;
}

}

there are three relationships between User and Product

as well as this is how I instantiate the MobileServerClient

public static void initiate(Context context) throws MalformedURLException {
    mClient = new MobileServiceClient(LINK,context).withFilter(new ProgressFilter());
    mClient.setAndroidHttpClientFactory(new OkHttpClientFactory() {
        @Override
        public OkHttpClient createOkHttpClient() {
            OkHttpClient client = new OkHttpClient();
            client.setReadTimeout(20, TimeUnit.SECONDS);
            client.setWriteTimeout(20, TimeUnit.SECONDS);
            return client;
        }
    });
    initiateTables();
}

public static void initiateTables(){
    mUserManager = mClient.getTable("User",User.class);
    mProduct = mClient.getTable("Product",ProductImp.class);
    mMail = mClient.getTable("Mail",Mail.class);
    mLockerImp = mClient.getTable("Locker",LockerImp.class);
    mCart = mClient.getTable("Cart",CartList.class);
}

Here is my back-end database schema of User table I changed all of the attributes to Upper-Case in first word otherwise an error will occur.

enter image description here

thanks a lot.


Solution

  • Try to modify url http to https.