/crystal-map

framework to generate map based entities classes / classes for named map interaction / parsing of complex classes to map structures

Primary LanguageKotlinMIT LicenseMIT

[Build Status codecov

CrystalMap Logo

A Framework for all Mapheads out there

What is this Framework about?

  • generate pojos for easy map interactions (@MapWrapper)
  • entity framework for all databases which represents it's data in maps (@Entity)
  • serialise/deserialise objects of complex classes in maps (@Mapper)

Quick View

@Entity / @MapWrapper

@Entity(database = "mydb_db")
@Fields(
        Field(name = "type", type = String::class, defaultValue = "product", readonly = true),
        Field(name = "name", type = String::class),
        Field(name = "comments", type = UserComment::class, list = true),
        Field(name = "image", type = Blob::class),
        Field(name = "identifiers", type = String::class, list = true)
)
@Queries(
        Query(fields = ["type"])
)
open class Product
@MapWrapper
@Fields(
        Field(name = "comment", type = String::class),
        Field(name = "user", type = String::class, defaultValue = "anonymous"),
        Field("age", type = Integer::class, defaultValue = "0")
)
open class UserComment

Result

        ProductEntity
                .create()
                .builder()
                .setName("Beer")
                .setComments(listOf(UserCommentWrapper
                        .create()
                        .builder()
                        .setComment("very awesome")
                        .exit()))
                .setImage(Blob("image/jpeg", resources.openRawResource(R.raw.ic_kaufland_placeholder)))
                .exit()
                .save()

        val allEntitiesOfType = ProductEntity.findByType()
        val resultOfAComplexQuery = ProductEntity.someComplexQuery("foo")

@Mapper

@Mapper
class MyViewModel : ViewModel() {

    @Mapify
    var innerObjectList: List<MyMapifyableTest> = listOf(MyMapifyableTest(simple))

    @Mapify
    var innerObjectMap: Map<String, MyMapifyableTest> = mapOf("test" to MyMapifyableTest(simple))

    @Mapify
    var testSerializable: TestSerializable = TestSerializable(simple, 5)

    @Mapify(nullableIndexes = [0])
    var product: ProductEntity? = null

    @Mapify
    var booleanValue: Boolean = true

    @Mapify(nullableIndexes = [0])
    var bigDecimalValue: BigDecimal? = null
}

Result

  // This is generated by the Annotation Processor
  val mapper = MyViewModelMapper()
  val oldObj = ViewModelProvider(this).get(MyViewModel::class.java)

  // Save obj to Map
  val mapToPersist = mapper.toMap(oldObj)

  val newObj = ViewModelProvider(this).get(MyViewModel::class.java)
  // restore obj
  mapper.fromMap(newObj, mapToPersist)

Implementation