Representer.defaultFlowStyle is always overridden by default value

Issue #383 resolved
Roman Kishchenko created an issue

Currently, if default flow style is configured on Representer level, it's always overridden in Yaml constructor:

Representer representer = new Representer();
representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(representer);

Yaml(representer) calls this(new Constructor(), representer) -> this(constructor, representer, new DumperOptions()) and eventually this(constructor, representer, dumperOptions, new LoaderOptions(), new Resolver())

In the body of the last constructor some Presenter properties are overridden by the default properties of DumperOptions, which is not expected behaviour, from my perspective:

representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle());
representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle());
representer.getPropertyUtils()
        .setAllowReadOnlyProperties(dumperOptions.isAllowReadOnlyProperties());
representer.setTimeZone(dumperOptions.getTimeZone());

Comments (4)

  1. Roman Kishchenko reporter

    1) I expect that with this configuration default flow style will be BLOCK, however it's FLOW:

    Representer representer = new Representer();
    representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    Yaml yaml = new Yaml(representer);
    

    It's not obvious and I spent a while to figure out why it didn't work

    2) Simple solution is initialize DumperOptions by the configuration from Representer. Replace new DumperOptions() by createDumperOptions(Representer)

  2. Andrey Somov

    Sorry, but after your explanation it does not become clear.

    Can you please create a pull request or attach here a patch with the expected changes (and tests to see the usage) ?

  3. Log in to comment