Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

json - Gradle or jackson fasterxml @JsonProperty not working

Android App development with Androidx Java, Gradle and Firebase.

Please help me to find out, why @JsonProperty is not working.

Gradle has set fasterxml library successfully.
There are no compile time error, or runtime error.
FasterXML Library also has been installed and exist.

But @JsonProperty and @Jsonignore don't work.
So instead of storing data, with the name, declared in the @JsonProperty,
data are stored into firebase with variable name.

and @JsonIgnore doesn't ignore the variable,
and they are stored into the firebase too.

Below is the build.gradle, please help me to find out the root cause.

apply plugin: 'com.android.application'
apply from: "$project.rootDir/tools/checkstyle.gradle"
apply from: "$project.rootDir/tools/pmd.gradle"

repositories {
   google()
   mavenCentral()
   maven {
            url "https://repo.spring.io/libs-milestone/"
   }
   maven {
            url "https://repository.mulesoft.org/nexus/content/repositories/public/"
   }
}

android {
    lintOptions {
        abortOnError false
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'        
        resolutionStrategy.force 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
        resolutionStrategy.force 'com.fasterxml.jackson.core:jackson-core:2.2.2'
        resolutionStrategy.force 'com.fasterxml.jackson.core:jackson-annotations:2.2.2'
    }
    signingConfigs {
        config {
            keyAlias '*****'
            keyPassword '*****'
            storeFile file('*****')
            storePassword '*****'
        }
    }
    flavorDimensions "default"
    compileSdkVersion 30
    defaultConfig {
        applicationId "*****"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 17
        versionName "Basilisk-prd"
        signingConfig signingConfigs.config
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            testCoverageEnabled = true
        }
    }
    productFlavors {
        staging {
            applicationIdSuffix ""
            versionNameSuffix "-stg"
        }

        production {
            applicationIdSuffix ""
            versionNameSuffix "-prd"
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/androidx.*'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    buildToolsVersion '30.0.1'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
    androidTestImplementation 'androidx.annotation:annotation:1.0.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test:rules:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
    androidTestImplementation('androidx.test.espresso:espresso-contrib:3.1.0') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
    androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    implementation('commons-lang:commons-lang:2.6') {
        exclude group: 'commons-io', module: 'commons-io'
    }

    //Butterknife
    implementation 'com.jakewharton:butterknife:10.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'

    //Dagger2
    implementation 'com.google.dagger:dagger:2.15'
    implementation 'com.google.dagger:dagger-android:2.15'
    implementation 'com.google.dagger:dagger-android-support:2.15'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.15'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.15'

    // Architecture
    implementation 'androidx.lifecycle:lifecycle-runtime:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'

    // RX Java
    implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

    implementation 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.2.2'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.2.2'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.2.2'

    implementation platform('com.google.firebase:firebase-bom:26.1.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-database'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'commons-io:commons-io:2.4'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'me.dm7.barcodescanner:zxing:1.8.4'
    implementation 'com.journeyapps:zxing-android-embedded:3.5.0'
    implementation 'com.journeyapps:zxing-android-embedded:3.3.0@aar'
    implementation 'com.google.zxing:core:3.2.1'
    implementation 'com.github.bumptech.glide:glide:4.2.0'

    // (AH) for HTTP requests
    implementation 'com.squareup.retrofit2:retrofit:2.6.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
}

apply plugin: 'com.google.gms.google-services'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Latest Firebase Database doesn't use @JsonProperty @JsonIgnore from fasterxml jackson annotation anymore.

Instead use @PropertyName @Exclude @IgnoreExtraProperties from package com.google.firebase.database


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...