Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create converter #214

Open
sumeet-chaayos opened this issue Aug 14, 2017 · 3 comments
Open

Unable to create converter #214

sumeet-chaayos opened this issue Aug 14, 2017 · 3 comments

Comments

@sumeet-chaayos
Copy link

sumeet-chaayos commented Aug 14, 2017

Getting unable to create converter on using retrofit with logansquare as convertor . I have already added the apt and gradle dependency as given on homepage
Caused by: java.lang.IllegalArgumentException: Unable to create converter for java.util.List<com.chaayos.android.model.UnitBasicDetail> for method LoginService.getUnits at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:752) at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:738) at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:169) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170) at retrofit2.Retrofit$1.invoke(Retrofit.java:147) at java.lang.reflect.Proxy.invoke(Proxy.java:397) at $Proxy1.getUnits(Unknown Source) at com.chaayos.kettle.android.login.AssemblyLoginFragment.populateUnitsList(AssemblyLoginFragment.java:240) at com.chaayos.kettle.android.login.AssemblyLoginFragment.onCreateView(AssemblyLoginFragment.java:123) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601) at com.chaayos.kettle.android.assembly.AssemblyScreenActivity.onStart(AssemblyScreenActivity.java:214) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1244) at android.app.Activity.performStart(Activity.java:6108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2491) ... 10 more Caused by: java.lang.IllegalArgumentException: Could not locate ResponseBody converter for java.util.List<com.chaayos.android.model.UnitBasicDetail>. Tried: * retrofit2.BuiltInConverters * com.github.aurae.retrofit2.LoganSquareConverterFactory at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:351) at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313) at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:736) ... 28 more

Below is the class
`
@JsonObject(fieldDetectionPolicy = JsonObject.FieldDetectionPolicy.NONPRIVATE_FIELDS_AND_ACCESSORS)
public class UnitBasicDetail {

@JsonField
private int id;
@JsonField
private String name;
@JsonField
private String category;
@JsonField
private int noOfTerminal;
@JsonField
private boolean tokenEnabled;

public UnitBasicDetail() {
	// Used for LoganSquare deserialization
}
public UnitBasicDetail(int id, String name, String category, int noOfTerminal) {
	super();
	this.id = id;
	this.name = name;
	this.category = category;
	this.noOfTerminal = noOfTerminal;
}

public int getId() {
	return id;
}

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

public String getName() {
	return name;
}

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

public String getCategory() {
	return category;
}

public void setCategory(String category) {
	this.category = category;
}

public int getNoOfTerminal() {
	return noOfTerminal;
}

public void setNoOfTerminal(int noOfTerminal) {
	this.noOfTerminal = noOfTerminal;
}

public boolean isTokenEnabled() {
	return tokenEnabled;
}

public void setTokenEnabled(boolean tokenEnabled) {
	this.tokenEnabled = tokenEnabled;
}

@Override
public boolean equals(Object obj) {
	if(obj instanceof UnitBasicDetail ){
		if(this.getId() == ((UnitBasicDetail)obj).getId()){
			return true;
		}
	}
	return false;
}

}`

@mannodermaus
Copy link
Contributor

Retrofit's stack trace mentions that the LoganSquareConverterFactory was successfully found and queried, but it couldn't handle your class. Could you share your module's build.gradle file as well? It seems like the annotation processor doesn't generate a JsonMapper for your class, and it fails trying to look it up from Retrofit. This leads me to believe that the processor is applied incorrectly. Also, can you check your generated sources (build/generated/...) for a class named UnitBasicDetail$$JsonMapper?

@sumeet-chaayos
Copy link
Author

sumeet-chaayos commented Aug 16, 2017

@aurae You are right, annotation processsor module is not added to gradle ,where my model classes are defined ,that's why its unable to generate JsonMapper .After adding it in that module gradle it works. But i have a doubt :- Earlier my all java classes are in a Model named module, which is defined as "java" moduloe in gradle (and it should be like that only as it contains only pure java classes), But just because of need of adding Annotation processor dependency, I have to make it a "Android" module with manifest and all . Although i have added annotation processor in my main android module dependency where this Model module is included , but still it works only when its added on the root module where the class is defined. Can there be any solution to that so that i dont have to make my Model java module with pure java classes only to a android module just because of annotation processor.

@mannodermaus
Copy link
Contributor

mannodermaus commented Aug 16, 2017

You can totally use annotation processing in a pure-Java Gradle module! I used to recommend this plugin to folks for this (not sure about the current state of first-party support in the Java plugin). Apply it to your "models" module, then declare the LoganSquare processor as an apt dependency to that module. When building, it should generate the JsonMapper as well - check with a clean build to make sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants