bluelinelabs / LoganSquare

Screaming fast JSON parsing and serialization library for Android.
Apache License 2.0
3.21k stars 306 forks source link

com.bluelinelabs.logansquare.NoSuchMapperException: Class in.manasviniganesh.ostracon.ostracon.Message could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject? #209

Open ManasviniGanesh opened 7 years ago

ManasviniGanesh commented 7 years ago

## This error has been bothering me since days. LoganSquare's dependencies were installed along with Salut WiFi Library. I am using Salut and LoganSquare.

com.bluelinelabs.logansquare.NoSuchMapperException: Class in.manasviniganesh.ostracon.ostracon.Message could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject?
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.bluelinelabs.logansquare.LoganSquare.mapperFor(LoganSquare.java:304)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.bluelinelabs.logansquare.LoganSquare.serialize(LoganSquare.java:149)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.peak.salut.BackgroundDataSendJob.doOnBackground(BackgroundDataSendJob.java:45)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.arasthel.asyncjob.AsyncJob$2.run(AsyncJob.java:59)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at java.lang.Thread.run(Thread.java:818)

# My gradle file

com.bluelinelabs.logansquare.NoSuchMapperException: Class in.manasviniganesh.ostracon.ostracon.Message could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject?
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.bluelinelabs.logansquare.LoganSquare.mapperFor(LoganSquare.java:304)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.bluelinelabs.logansquare.LoganSquare.serialize(LoganSquare.java:149)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.peak.salut.BackgroundDataSendJob.doOnBackground(BackgroundDataSendJob.java:45)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at com.arasthel.asyncjob.AsyncJob$2.run(AsyncJob.java:59)
05-06 02:41:58.911 24358-26985/in.manasviniganesh.ostracon W/System.err:     at java.lang.Thread.run(Thread.java:818)
mannodermaus commented 7 years ago

It seems like you've accidentally pasted the stack trace twice. Could you share your build.gradle & the Message class as well? From what I can from Salut's readme file, they don't seem to advertise the latest version of LoganSquare, so maybe your issue can already be resolved by simply upgrading to 1.3.7.

Aawesh commented 7 years ago

Hi, did you find any solution to this ?

VitorFontenelle commented 7 years ago

I am using the same way as her (Salut), and I am getting the same error, so I think we may have a close build.gradle. For the record, I already tried using 1.3.6 and 1.3.7. If possible, show me what am I doing wrong:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.jotakape.interit.jokenpo"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.github.markrjr:Salut:v0.4.9'
    annotationProcessor 'com.github.markrjr:Salut:v0.4.9'
    compile 'com.bluelinelabs:logansquare:1.3.7'
    annotationProcessor 'com.bluelinelabs:logansquare:1.3.7'
    compile 'com.squareup:javapoet:1.2.0'
    annotationProcessor 'com.squareup:javapoet:1.2.0'
}

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

Also, here is my Message class:

@JsonObject
public class Message {

    /*
     * Annotate a field that you want sent with the @JsonField marker.
     */
    @JsonField
    public String description;
}
mannodermaus commented 7 years ago

It's odd that your build.gradle file contains two independent dependencies blocks. I mean, it shouldn't theoretically be a problem, but can you merge their contents and try again? Also, do you see any generated code in your module's build/generated/source/apt folder?

VitorFontenelle commented 7 years ago

I merged them together and updated the previous comment, but the error was still the same. My build/generated/source/apt folder only contains an empty "debug" folder.

VitorFontenelle commented 7 years ago

I actually got it working, it was kind of a dumb mistake, but... I only added theses two following lines in the dependencies and it started working:

    compile 'com.bluelinelabs:logansquare-compiler:1.3.7'
    annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.7'

I was caught by the Gradle trap. Found randomly in the internet that this wasn't enough:

    compile 'com.bluelinelabs:logansquare:1.3.7'
    annotationProcessor 'com.bluelinelabs:logansquare:1.3.7'
mannodermaus commented 7 years ago

Oh wow, I didn't even spot that one either. Yes, there are two separate artifacts to LoganSquare, logansquare and logansquare-processor. Glad you found it out!