objectbox / objectbox/objectbox-java

Store Map values as Long instead of Int

Open
#1,181 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Java
Stars
4.6k
Forks
311
PR merge metrics
No merged PRs in 30d

Description

Is there an existing issue?
Use case

I am storing a mapping:

val mapping = mutableMapOf(
    "key1" to mutableMapOf(
        "subkey1" to 1L,
        "subkey2" to 1L,
        "subkey3" to 1L
    ),
   "key2" to 1L

that is represented in the data class as follows:

@Entity
data class MyDataClass(
    @Id var id: Long = 0,
    var mapping: MutableMap<String, Any>? = null

ObjectBox will store the Long values as Ints due to not being wide enough. These breaks use cases where we do want to store the Long values as Long and not as Ints (for example test cases that use the same generated mock data to store in the database and to test against).

Proposed solution

Have an annotation that tells ObjectBox to store Long values as Long.

Alternatives

Tried using a PropertyConverter however this breaks for the mapping I've provided.

Additional context

Kotlin
Android

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Start by tracing how MutableMap<String, Any> values are serialized and why the attempted PropertyConverter does not work for this mapping; then define how the proposed annotation should preserve Long values and verify the stored and retrieved values remain Long.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
database, mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.