smoope / j2objc-maven-plugin

Maven plugin for J2ObjC library
Apache License 2.0
6 stars 11 forks source link

ArrayStoreException: Unable to use gson in swift framework #15

Open sardarasmita opened 3 years ago

sardarasmita commented 3 years ago

I am trying to get Gson through j2objc such that I can use it for my iOS swift framework. I am using J2ObjC 2.8 and GSON 2.8.5. and all the classes are translating correctly. However, while running the tests, I cannot successfully convert the data using GSON as the function throws the error.

Java Code

public class Request {
    private String name;
    private String description;

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

    public String getName() {
        return name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }    
}
public class AService {
    public String getGsonString(Request request) {
        Gson gson = new Gson();
        return gson.toJson(request);
    }
}

I am using the converted code of the above code to run the test case in the swift project

func testGsonString(){
        let request = ComRequest()
        request?.setNameWith("name")
        request?.setDescriptionWith("description")
        let response = ComAService().getGsonString(with: request!)
        XCTAssertNotNil(response)
    }

While running the above code, The ComAService().getGsonString(with: request!) throws error

I have used j2objc-maven-plugin 1.1.4 for conversion and gson 2.8.5.

I require gson to convert string to object or object to a string so that I can use the converted string to store in the local database and vice versa

130604697-9a487673-8692-47f4-888a-6d5652e337bf 130604735-578ae5d5-ce31-4386-8c4f-22251c606b19
vicmosin commented 3 years ago

Hi @sardarasmita , tbh I am not sure that your issue somehow related to j2objc-maven-plugin.. might be a bug in j2objc itself? Can you try it with later versions of the lib, since this plugin wasn't updated for a long time already..