Skip to content

Conversation

@ihostage
Copy link

Current implementation doesn't give users any chance to control the property name in Hocon representation when they use the useConfigNamingConvention.

}

@Test
fun testDeserializeUsingSerialNameInsteadOfNamingConvention() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was successful only because the value in @SerialName is follow the naming convention 😄
I think it is confusing and not helpful to check anything.

@ihostage
Copy link
Author

@sandwwraith, have I a chance to get review and merge this fix?
I can't continue my work on the config4k library without it. 😞

@sandwwraith
Copy link
Member

I'm a little bit hesitant to add this annotaiton for Hocon, since we do not have a Json equivalent; if same problem arises in Json (it is there for JsonNamingStrategy, for example), maybe we would need a better generalized solution.

What are benefits of having this annotation instead of just disabling "useHoconNamingConvention"? Or maybe we need a specific annotation, e.g., @DisableHoconConvention instead? I imagine it can be quite confusing if I had @HoconName("fooBar") @SerialName("fooBar") on the same property

@ihostage
Copy link
Author

ihostage commented Nov 4, 2025

What are benefits of having this annotation instead of just disabling "useHoconNamingConvention"?

I don't want to disable this naming convention, because 99% of the fields follow this convention. However, we also need the ability to set a serial name manually from time to time. 🤷‍♂️

Or maybe we need a specific annotation, e.g., @DisableHoconConvention instead?

Yes, potentially this solves the problem by using two annotations per field, but it doesn't look so good either. 🤔

@Serializable
data class (
  @DisableHoconConvention
  @SerialName("unConventionField") 
  val unConventionField: String
)

I imagine it can be quite confusing if I had @HoconName("fooBar") @SerialName("fooBar") on the same property

Do you mean the situation where one type can be serialized in multiple formats?

since we do not have a Json equivalent

We have the @JsonNames annotation as an alternative name for fields. Perhaps using alternative names instead of overriding the serial name with a special annotation would be a more preferable approach for you. 🤔

@pdvrieze
Copy link
Contributor

pdvrieze commented Nov 4, 2025

I have looked the options for not having per-format naming annotations. I am not sure that those annotations can be avoided if you want to be able to use the same serializers for different formats (with potentially different names). Even if a functional strategy is used, it would often have to resort to either a built-in translation table or custom annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants