Skip to content

JsonAnyGetter doesn't work with JsonSerialize (except with keyUsing) #705

@natnan

Description

@natnan

(This is happening with 2.5.0. Haven't tried 2.5.1 but I couldn't see any related issue anyway)

Jackson ignores JsonSerialize annotation when there is JsonAnyGetter annotation.

  @JsonSerialize(using = MySerializer.class)
  // or
  @JsonSerialize(converter = MyConverter.class)
  @JsonAnyGetter
  public Map<String, String> getParameters(){
    return parameters;
  }

except

@JsonSerialize(keyUsing = MyKeySerializer.class)

(haven't tried each setting. Only tried keyUsing because I've seen a different issue (#661) with it)
Then it works. But I need the converter, so..

For the time being I will use

  @JsonAnyGetter
  public Map<String, JsonNode> getParameters(){
    return new MyConverter().convert(parameters);
  }

but I'd prefer to stick to annotations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions