[Resolved] hi, guys i have some trouble during wor...
# announcements
v
[Resolved] hi, guys i have some trouble during working with jakson. i wrote next class
Copy code
class NeuralNetworkModelingModuleInput (
    @JsonProperty("module")
    val ModuleName: String = "neural_network_modeling",
...
)
I expects that field ModuleName would be mapped to "module" field of json. And for deserialization its work correct, but when i try to serialize this class, i get json with field "moduleName". Seems like object mapper simply ignore JsonProperty annotation. Also this may ocurred cause of for deserialization i use mapper in ktor server, and standalone mapper for serialization:
Copy code
private fun<T> serialize(obj: T): String {
        return mapper
            .configure(SerializationFeature.INDENT_OUTPUT, true)
            .writeValueAsString(obj)
    }
Can anyone please help me?
solve this issue by adding
Copy code
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
this annotation to my class. but now occured another problem: all fields was duplicated after serialization. For example, for fied ModuleName with JsonName module after serialization exist both fields: module and ModuleName
"module" : "neural_network_modeling",
"moduleName" : "neural_network_modeling"
u
You may try to rename the moduleName to module in your class
v
ok, thats would work. but for another field(for example nEpoch) didnt. nEpoch serialized as nepoch, but i expected n_epoch
u
It has one working example
v
ooo, thanks!
Unfortunately method described in this article didn't help me 🤔
d
Instead of @JsonProperty try changing to @get:JsonProperty
👍 1
Does your mapper have the kotlin module registered?
v
Yes, it registered
@Dave K Thanks a lot! That helps me. Reason of this unexpected behaviour was that i use annotations in constructor instead of standard fields
👍 1