objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.4k stars 302 forks source link

Support serialization for property that is an object #1069

Open NBXXF opened 2 years ago

NBXXF commented 2 years ago

您好,我期望自定义类型 能更好的支持二进制,提高速度,是否可以参考 https://github.com/twitter/Serial 这样更方便的将字段是自定义模型 更快插入和读取

Translation: Hello, I hope that the custom type can better support binary and improve the speed. Can you refer to https://github.com/twitter/Serial This makes it more convenient to insert and read the field into a custom model faster

ivahnenkoAnna commented 2 years ago

Thank you for the feature request. We are looking into this and will reply as soon as possible.

greenrobot-team commented 2 years ago

You can already store byte arrays in an object, see built-in support for types: https://docs.objectbox.io/advanced/custom-types#objectbox-supported-types

If this is about completely replacing the class model (e.g. classes annotated with @Entity containing fields that are properties) then I don't think this makes sense. ObjectBox already uses a binary format behind the scenes (FlatBuffers) to store objects. Could you elaborate on your idea then?

NBXXF commented 2 years ago

You can already store byte arrays in an object, see built-in support for types: https://docs.objectbox.io/advanced/custom-types#objectbox-supported-types

If this is about completely replacing the class model (e.g. classes annotated with @Entity containing fields that are properties) then I don't think this makes sense. ObjectBox already uses a binary format behind the scenes (FlatBuffers) to store objects. Could you elaborate on your idea then?

关键性能在于转二进制 以及持久化的二进制如何完整反序列化 不出现兼容字段问题,行业有cryo flatbuffers 等 我的场景是 UserPo.xxxField 是一个对象

Translation: The key performance lies in how to convert the binary and how to completely deserialize the persistent binary without the problem of compatible fields. The industry has cryo flatbuffers, etc. My scenario is UserPo.xxxField is an object

greenrobot-team commented 2 years ago

Using the current ObjectBox API this should be solvable in a technology independent way using @Convert and a PropertyConverter that de/serializes objects. https://docs.objectbox.io/advanced/custom-types#convert-annotation-and-property-converter

E.g. you could write a converter that uses https://github.com/twitter/Serial as you suggested.