moshi-kotlin-ignore

Additional

Language
Kotlin
Version
0.0.3 (Nov 5, 2017)
Created
Nov 5, 2017
Updated
Nov 5, 2017
Owner
Shuma Yoshioka (S64)
Contributor
Shuma Yoshioka (S64)
1
Activity
Badge
Generate
Download
Source code

Advertisement

moshi-kotlin-ignore

TL;DR: Moshi version of Jackson's @JsonIgnore. For when you can't use @Transient.

In Moshi, You can use transient keyword (in Kotlin: @Transient annotation) for ignore serialization.
But sometimes it's conflict to other features. e.g. ebean-querybean.

moshi-kotlin-ignore is library for ignore parameter serialization / deserialization. You can use this library to resolve above issues.

Usages

First, Add following lines to your buildscripts:

buildscript {
  ext {
    mki_version = '0.0.3'
  }
}
repositories {
  maven { url 'http://dl.bintray.com/s64/maven' }
}

dependencies {
  compile "jp.s64.kotiln:moshi-kotlin-ignore:${mki_version}"
}

Next, Add factory to your Moshi builder.

// import jp.s64.kotlin.moshi.ignore.IgnoreAdapter

Moshi.Builder()
  //.add(KotlinJsonAdapterFactory())
  .add(IgnoreAdapter.FACTORY)
  .build()

For example: You can use in data class's value parameter.

// import jp.s64.kotlin.moshi.ignore.Ignore

data class MyItem(
  val id: Long
  @Ignore
  val secret: String
)

@Ignore is easy to make conflict? Don't worry, Kotlin has typealias feature 😉.

// import jp.s64.kotlin.moshi.ignore.Ignore

typealias MyMagicalAnnotationOfIgnoreJsonPropertyLikeJsonIgnore = Ignore

data class MyAwesomeObjectOfHoldUsersSecretForSignIn(
  val id: Long
  @MyMagicalAnnotationOfIgnoreJsonPropertyLikeJsonIgnore
  val secret: String
)

License

Copyright 2017 Shuma Yoshioka

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.