Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add @HoconName annotation#3013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ihostage wants to merge1 commit intoKotlin:dev
base:dev
Choose a base branch
Loading
fromihostage:hocon-name-annotation

Conversation

@ihostage
Copy link

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

}

@Test
funtestDeserializeUsingSerialNameInsteadOfNamingConvention() {
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

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. 🤔

@Serializabledataclass (  @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

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.

@sandwwraith
Copy link
Member

@ihostage

Do you mean the situation where one type can be serialized in multiple formats?
Yes. In case I have a class serialized both to Hocon and Json, it is possible to end up in this situation. Although it can indeed be quite rare.

We have the @JsonNames annotation as an alternative name for fields

It works for deserialization alone.@HoconName though affects encoding as well. If you think that this problem is specific to deserialization, yes,@JsonNames analogue would be preferable.

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@ihostage@sandwwraith@pdvrieze

[8]ページ先頭

©2009-2025 Movatter.jp