David Silva
02/12/2025, 3:15 PMDavid Silva
02/12/2025, 3:16 PMdata class Config(val list: List<Element>)
data class Element(val a: String, val b: String, val c: String)
Yaml file (config):
defaults: &def
a: a-value
b: b-value
list:
- <<: *def
c: c1-value
- <<: *def
c: c2-value
Error:
- Could not instantiate 'Config' because:
- 'list': Collection element decode failure (classpath:/test.yaml:5:2):
- Could not instantiate 'Element' because:
- 'a': Missing from config
- 'b': Missing from config
- Could not instantiate 'Element' because:
- 'a': Missing from config
- 'b': Missing from config
sam
02/12/2025, 4:30 PMsam
02/12/2025, 4:30 PMChris Lee
02/12/2025, 4:38 PM• The mergehttps://yaml.org/spec/1.2.2/ext/changes/#:~:text=The%20most%20significant%20difference%20between,the%20YAML%201.1%20type%20library.and value<<
special mapping keys have been removed.=
David Silva
02/12/2025, 6:46 PMDavid Silva
02/12/2025, 6:48 PMDavid Silva
02/17/2025, 12:09 PM<<
), rather than merging its fields into the current node.
So this:
defaults: &def
a: a-value
b: b-value
list:
- <<: *def
c: c1-value
Sort-of turns into:
list:
- <<:
a: a-value
b: b-value
c: c1-value
Thus it won’t be able to see a
and b
directly on that list element, throwing the error that I’ve included above (1st message on this thread).
I’ve implemented a (quick) fix - not sure if it’s the best approach, but at least serves as a baseline to see merge-keys working.
https://github.com/sksamuel/hoplite/compare/master...davidafsilva:hoplite:feature/merge-keys-support
Would you be interested in supporting this in hoplite-yaml, or do you think it might not be worth the effort?