Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectMapper configuration should apply when pretty printing #5094

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

tsegismont
Copy link
Contributor

@tsegismont tsegismont commented Feb 5, 2024

Follows-up on #5060

Since the pretty mapper is deprecated, any customization of the object mapper should be used when pretty printing with Json.encodePrettily.

Since the pretty mapper is deprecated, any customization of the object mapper should be used when pretty printing with Json.encodePrettily.

And then it is no longer necessary to create the pretty mapper config by default, so we can lazily create it.

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
@tsegismont tsegismont added this to the 4.5.3 milestone Feb 5, 2024
@tsegismont tsegismont requested a review from vietj February 5, 2024 16:27
Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
@vietj vietj merged commit 3ab73e0 into eclipse-vertx:4.x Feb 6, 2024
7 checks passed
@tsegismont tsegismont deleted the no-pretty-mapper-internally branch February 6, 2024 09:17
@magicprinc
Copy link
Contributor

magicprinc commented Feb 7, 2024

It is better to use a customized DefaultPrettyPrinter:

objectMapper.setDefaultPrettyPrinter(new Pretty());// .writerWithDefaultPrettyPrinter()


private static final class Pretty extends DefaultPrettyPrinter {
  public Pretty (DefaultPrettyPrinter base){
    super(base);  
    fix();
  }

  Pretty (){
    fix();
  }

  private void fix (){
    _objectFieldValueSeparatorWithSpaces = ": ";// otherwise: "propertyName" : 1 < extra space before :
    _objectIndenter = new DefaultIndenter("  ", "\n");// 2 spaces (no changes), LF (vs \r\n on Windows)
  }

  @Override
  public DefaultPrettyPrinter createInstance (){
    return new Pretty(this);
  }
}

@magicprinc
Copy link
Contributor

io.vertx.core.json.jackson.DatabindCodec#mapper must be created with JacksonCodec#factory (with HybridJacksonPool

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.

None yet

3 participants