LoginSignup
0
0

More than 1 year has passed since last update.

【Android Studio】Gradleでの Jackson の追加方法(Java)

Posted at

Android Studioを使用したJacksonの使用方法について調べたのですが、実装までに四苦八苦したので、メモを残しておきます。

リポジトリ

Jacksonが公開されているページです。
ページ内の取得したいバージョンの「Gradle」の部分をコピーします。
jackson-core
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
jackson-databind
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
jackson-annotations
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations

使用するバージョンの選択

a010b5d5-04f0-c700-22a2-08b424747a45.png

build.gradleに貼り付ける箇所のコピー

fcc89578-fbe5-fb63-983f-fe01769be76a.png

build.gradle

ライブラリの管理はbuild.gradleで行われているので、先ほどコピーした内容をbuild.gradledependenciesに追加します。

build.gradle
plugins {
    id 'com.android.application'
}

android {
    // 省略
}

dependencies {
    // ここに追加する
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.13.0'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.0'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.13.0'

    // 以下はデフォルトの内容
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

追加した後に再ビルドをすれば、読み込み完了です。

あとは、Javaのコードで、下記の様にjacksonのライブラリをimportすればandroid studioで、Jacksonが使用できるようになります。
(私の場合は、ObjectMapperreadValuewriteValueAsStringぐらいしか使わないため、ObjectMapperimportしています。)

import com.fasterxml.jackson.databind.ObjectMapper;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0