Unable To Apply Formatting To SnakeYaml Upon Serialisation

17 afișări
Accesați primul mesaj necitit

Bhrein Brannick

necitită,
23 apr. 2020, 08:00:5223.04.2020
– SnakeYAML
Hi there,

I opened this issue to Jackson regarding customising the Serialisation of a pojo

https://github.com/FasterXML/jackson-dataformats-text/issues/185

They have informed me that it's essentially low level thinkering of the SnakeYaml settings. From looking at that code base within `Jackson` I found the Snake classes that does that.

Atm Jackson produces sample yaml like so

name: "OuterYamlElementName"
label: "OuterYamlElementLabel"
fields:
label: "outerYamlFieldLabel"
value: "outerYamlFieldValue"
isRequired: true
toggle: "+BEYWAYS-Outer-Yaml-Field"
elements:
name: "InnerYamlElementDepthOneName"
label: "InnerYamlElementDepthOneLabel"
fields:
- label: "innerYamlFieldsDepthOneItemOneLabel"
value: "innerYamlFieldsDepthOneItemOneValue"
isRequired: true
toggle: "-BEYWAYS-Inner-Yaml-Fields-Depth-One-Item-One"
- label: "innerYamlFieldsDepthOneItemTwoLabel"
value: "innerYamlFieldsDepthOneItemTwoValue"
isRequired: false
toggle: "-BEYWAYS-Inner-Yaml-Element-Depth-One"
toggle: "+BEYWAYS-Outer-Yaml-Element"

however I'd like the yaml to be generated like so:

name: "OuterYamlElementName"
label: "OuterYamlElementLabel"
fields:
- {label: "outerYamlFieldLabel", value: "outerYamlFieldValue", isRequired: true, toggle: "+BEYWAYS-Outer-Yaml-Field"}
elements:
name: "InnerYamlElementDepthOneName"
label: "InnerYamlElementDepthOneLabel"
fields:
- { label: "innerYamlFieldsDepthOneItemOneLabel", value: "innerYamlFieldsDepthOneItemOneValue", isRequired: true, toggle: "-BEYWAYS-Inner-Yaml-Fields-Depth-One-Item-One" }
- { label: "innerYamlFieldsDepthOneItemTwoLabel", value: "innerYamlFieldsDepthOneItemTwoValue", isRequired: false }
toggle: "-BEYWAYS-Inner-Yaml-Element-Depth-One"
toggle: "+BEYWAYS-Outer-Yaml-Element"

Reason been the Yaml produced is relatively big and I like it to be generated more condensed if possible (I'm only providing a sample atm).

Here is where those settings are configured

https://github.com/FasterXML/jackson-dataformats-text/blob/master/yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.java#L301

I have tried some other settings for example

opt.setDefaultFlowStyle(FlowStyle.Flow);
opt.setMultiLineFlow(true);

unfortunately to no avail. Would anybody know what settings are needed to create the desired structure above? Many thanks in advance.

Andrey Somov

necitită,
24 apr. 2020, 03:32:3324.04.2020
– snakeya...@googlegroups.com
Hi,
you can try to use
FlowStyle.AUTO

Cheers,
Andrey


--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/snakeyaml-core/a49da664-1530-4844-ae41-ba7bc46615da%40googlegroups.com.

Bhrein Brannick

necitită,
24 apr. 2020, 04:15:2524.04.2020
– SnakeYAML
Hi Andrey,

Tried that option too but that didn't work for me. Actually very little change in structure.

Cheers,

~Bhréin

Andrey Somov

necitită,
24 apr. 2020, 08:23:0924.04.2020
– snakeya...@googlegroups.com
YAML provides a zillion of ways to output a document.
Feel free to learn how it is done for AUTO and propose a more flexible way.

Cheers,
Andrey


--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.

Bhrein Brannick

necitită,
24 apr. 2020, 08:41:4024.04.2020
– SnakeYAML
Hi Andrey,

I cloned the Jackson repo & tweaked a lot of those `DumperSettings` that you are referencing in this thread. They didn't create the structure I'm looking for hence me asking.

I know when I serialise the pojo directly using Snake via `Yaml.dump()` I'm very close to getting the desired structure. I'm assuming that has default `DumperSettings`. Maybe if you point me to that it may help with the above.

Thanks again in advance as to any help with the above.

Cheers,

~Bhréin

Andrey Somov

necitită,
24 apr. 2020, 08:49:5924.04.2020
– snakeya...@googlegroups.com
If you already played with DumperOptions and it was not enough then you have to change the code.
Serializer creates sequence of Events from a Node.
Emitter translates Events to tokens.
Together they are flexible to output anything.

Good luck,
Andrey


--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.

Andrey Somov

necitită,
24 apr. 2020, 09:09:2624.04.2020
– snakeya...@googlegroups.com
For your information.
Jackson (in its master branch) already switched to SnakeYAML Engine.
It is probable better to implement your way in SnakeYAML Engine (https://bitbucket.org/asomov/snakeyaml-engine/src/master/)

Cheers,
Andrey

Bhrein Brannick

necitită,
24 apr. 2020, 09:23:3624.04.2020
– SnakeYAML
Hi Andrey,

Yes I seen that already. I looked at Jackson repo and from that I see that snakeyaml-engine was been uptaken.

In any case I will try some of the points you mentioned above in the thread. Have a nice day.

Best Regards,

~Bhréin

Andrey Somov

necitită,
24 apr. 2020, 09:35:0924.04.2020
– snakeya...@googlegroups.com
When this is accepted you can use the latest version.https://github.com/FasterXML/jackson-dataformats-text/pull/196
But nodes and events did not change at all.

Andrey


--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.

Bhrein Brannick

necitită,
24 apr. 2020, 09:47:5724.04.2020
– SnakeYAML
Nice. Maybe I'm missing something but doesn't that repo already use version 2.1

https://github.com/FasterXML/jackson-dataformats-text/blob/master/yaml/pom.xml#L32

The above link suggests that 2.1 is already up taken in master which is what I have been using for the last couple of days.

Andrey Somov

necitită,
24 apr. 2020, 10:19:5924.04.2020
– snakeya...@googlegroups.com
Thank you very much !!!
I forgot that I have already upgraded it :-)

Cheers,
Andrey


--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.

Uday Bhaskar Sarma Seetamraju

necitită,
28 apr. 2020, 10:33:2028.04.2020
– snakeya...@googlegroups.com
Please take a look at this answer on StackOverflow.. that is responding to a similar need.


--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.
Răspundeți tuturor
Răspundeți autorului
Redirecționați
0 mesaje noi