Git Product home page Git Product logo

entitymapper's Introduction

EntityMapper

  • @EntityMapper is an annotation that maps an entity class to a model class.
  • @PropertyName is an annotation that maps a field in the entity class to a field with a different name in the model class.

Sample Code

data class MemberEntity(
  val id: Int? = null,
  val name: String? = null,
  val age: Int? = null,
  val thumbnailUrl: String? = null,
  val collectionList: List<CollectionEntity>? = null,
  private val subscribeYn: String? = null
) {
  val isSubscribe: Boolean
    get() = subscribeYn.equals("y", true) == true
}

@EntityMapper(MemberEntity::class)
data class MemberUiModel(
  val id: Int,
  val name: String,
  val age: Int,
  val thumbnailUrl: String?,
  @PropertyName(["collectionList"]) val collections: List<CollectionModel>,
  val isSubscribe: Boolean
)
  1. @EntityMapper annotation usage
  2. Build the module or project using the following command
./gradlew :model:build or ./gradlew rebuild

If the build is successful, the following code will be generated.

fun MemberEntity.toMemberUiModel() = MemberUiModel(
  id = id!!,
  name = name!!,
  age = age!!,
  thumbnailUrl = thumbnailUrl,
  collections = collectionList?.map { it.toCollectionModel() } ?: emptyList(),
  isSubscribe = isSubscribe
)

Using in your projects

Add the KSP Gradle Plugin build.gradle(.kts)

plugin {
  id("com.google.devtools.ksp").version("1.9.24-1.0.20")
}

dependencies {
  implementation("com.github.sun5066:entitymapper:tag")
  ksp("com.github.sun5066:entitymapper:tag")
}

add to setting.gradle(.kts)

repositories {
  maven("https://jitpack.io")
}

entitymapper's People

Contributors

sun5066 avatar

Stargazers

박성현 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.