How to preserve string enum names

98 views
Skip to first unread message

mlic...@gmail.com

unread,
Nov 30, 2019, 9:02:33 AM11/30/19
to jsonschema2pojo-users
Hi

Currently string enum names are being modified (uppercased, camelcase causes underscores inserted) when the POJO is created.

This is unfortunate, as it's causing an inconsistency:
Serializing such a POJO (say, with a default ObjectMapper) will create JSON that is not actually compliant with the schema.

So my question, has anyone managed to configure jsonschema2pojo such that it does not modify enum names?  That'd very helpful.

Thanks
- Martin

PS: Yes there's 'javaEnumNames', but that's quite a workaround, and it's cumbersome and errorprone to maintain the same enum list twice.

Joe Littlejohn

unread,
Nov 30, 2019, 9:38:48 AM11/30/19
to jsonschema...@googlegroups.com
The ObjectMapper will use the value() method because it's annotated with @JsonValue. You'll see that the string held inside the value field in the enum is correct, even though the enum name follows the Java conventions.

These values will serialise correctly.

--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonschema2pojo-users/53326ff4-498e-4836-9c80-8ed05a58fb2b%40googlegroups.com.

mlic...@gmail.com

unread,
Nov 30, 2019, 10:10:29 AM11/30/19
to jsonschema2pojo-users
Thanks for the tip!
I had the maven plugin configured with <annotationStyle>none</annotationStyle> and that seems to have caused this issue.
With the default jackson2 annotationStyle, it works fine.

On Saturday, November 30, 2019 at 3:38:48 PM UTC+1, Joe Littlejohn wrote:
The ObjectMapper will use the value() method because it's annotated with @JsonValue. You'll see that the string held inside the value field in the enum is correct, even though the enum name follows the Java conventions.

These values will serialise correctly.

On Sat, 30 Nov 2019, 14:02 , <mlic...@gmail.com> wrote:
Hi

Currently string enum names are being modified (uppercased, camelcase causes underscores inserted) when the POJO is created.

This is unfortunate, as it's causing an inconsistency:
Serializing such a POJO (say, with a default ObjectMapper) will create JSON that is not actually compliant with the schema.

So my question, has anyone managed to configure jsonschema2pojo such that it does not modify enum names?  That'd very helpful.

Thanks
- Martin

PS: Yes there's 'javaEnumNames', but that's quite a workaround, and it's cumbersome and errorprone to maintain the same enum list twice.

--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages