Comments (3)
I do not plan to implement setter support for value class
at this time.
The reasons are as follows
- Requires a very complex implementation.
- It would degrade the overall performance of the
kotlin-module
as more reflection processing would be required. - Deserialization of
Kotlin
classes is generally done using constructors or factory functions, and there is theoretically no case where you must always use setters.
So, I am inlining a class that just contains an int (this improves performance and memory allocation in my application).
I would suggest benchmarking first.
For libraries using kotlin-reflect
, performance will degrade if you use the value class
.
Compared to using data class
, for example, the throughput of deserialization is roughly 70% (see the benchmark results in the link).
https://github.com/FasterXML/jackson-module-kotlin/blob/2.18/docs/value-class-support.md#note-on-the-use-of-value-class
from jackson-module-kotlin.
Requires a very complex implementation.
Yes, agreed. I thought that is something already.
I would suggest benchmarking first.
My application does not use jackson heavily, it is more something for reading and writing settings (and a couple of other things). The main improvement comes from memory allocation, the color class is not mutable, and I already started replacing colors with int in a lot of places. The memory allocation goes down by 30-50 MB/s, it makes the gc almost sleep. In my case the jackson sacrifize would be totally worth it (even if it is slower by 10 times) to make the code quality go up and not use ints in the code. But I guess this is only true in my case and a lot of people would not want to take this.
Thanks for the answer, I need to find a different way (maybe use a color wrapper class or so for config files).
from jackson-module-kotlin.
The main improvement comes from memory allocation
Hmmm, if that is the case, it might be preferable not to use jackson-module-kotlin
.
I haven't done a comparison, but as far as I know, this module uses more memory because it uses kotlin-reflect
.
If you are looking for performance, since Jackson
supports record classes, you might consider defining DTO
as JvmRecord
and not using kotlinModule
.
Alternatively, kotlinx-serialization
does not use reflection, which may also reduce runtime memory consumption (I believe value class
is also supported).
from jackson-module-kotlin.
Related Issues (20)
- Deserialization using default arguments fails when the creator parameter contains `value class` and the number is a multiple of 32.
- Serialization in Ktor project fails HOT 2
- Polymorphic sealed class missing type information
- mapper.updateValue allows to set fields to null which are not nullable HOT 1
- Incosistent behaviour with a single field
- Field proliferation bug when using ObjectMapper in Kotlin HOT 1
- @JsonProperty ignored when serialising Kotlin @JvmRecord in 2.16.X HOT 3
- Excessive memory usage when using KotlinModule with Kotlin data class HOT 2
- `NoSuchMethodError` for `com.fasterxml.jackson.module.kotlin.jacksonObjectMapper` after upgrading to 2.17.0 HOT 12
- Cannot use value class as map key in 2.17 HOT 8
- Can't compute ClassId for primitive type: int HOT 5
- Create 2.18 branch HOT 1
- How to disable the feature who rename a primitive boolean "isXXX" to "XXX" HOT 1
- Property enabledSingletonSupport - deprecated but with wrong template HOT 2
- Field with value class typ ignoring JsonProperty binding HOT 1
- 2.18 build on JDK 8 fails CI HOT 2
- Kotlin Module interferes with Java record deserialization HOT 4
- Missing classes error using AGP 8 R8 shrinker HOT 1
- Boolean property setter is skipped if name isX prefixed HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-module-kotlin.