Skip to content

declaringClass of "enum-as-POJO" not removed for ObjectMapper with a naming strategy #2365

@tynakuh

Description

@tynakuh

Happens in 2.9.9.

When you change ObjectMapper to use a different naming strategy, i.e:

ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

When serialising/using writeToString(Object value) for an object such as:

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Foo
{
    BAR("Foo", 0),
...

"declaring_class" will be added to the JSON payload.

Normally this is removed at:
com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java:1139 but because in
com.fasterxml.jackson.databind.introspect.BasicBeanDescription#removeProperty (It's only usage as far as I can see) we aren't using InternalName, declaringClass is not removed. Potential fix here is to change prop.getName() to prop.getInternalName(), a quick test of that seemed to work in my case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions