Commits
Wolf2323 authored and md_5 committed 5696668ab3f
93 93 | return writer.toString(); |
94 94 | } |
95 95 | |
96 96 | |
97 97 | public void loadFromString( String contents) throws InvalidConfigurationException { |
98 98 | Preconditions.checkArgument(contents != null, "Contents cannot be null"); |
99 99 | yamlLoaderOptions.setProcessComments(options().parseComments()); |
100 100 | |
101 101 | MappingNode node; |
102 102 | try (Reader reader = new UnicodeReader(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)))) { |
103 - | node = (MappingNode) yaml.compose(reader); |
104 - | } catch (YAMLException | IOException e) { |
103 + | Node rawNode = yaml.compose(reader); |
104 + | try { |
105 + | node = (MappingNode) rawNode; |
106 + | } catch (ClassCastException e) { |
107 + | throw new InvalidConfigurationException("Top level is not a Map."); |
108 + | } |
109 + | } catch (YAMLException | IOException | ClassCastException e) { |
105 110 | throw new InvalidConfigurationException(e); |
106 - | } catch (ClassCastException e) { |
107 - | throw new InvalidConfigurationException("Top level is not a Map."); |
108 111 | } |
109 112 | |
110 113 | this.map.clear(); |
111 114 | |
112 115 | if (node != null) { |
113 116 | adjustNodeComments(node); |
114 117 | options().setHeader(loadHeader(getCommentLines(node.getBlockComments()))); |
115 118 | options().setFooter(getCommentLines(node.getEndComments())); |
116 119 | fromNodeTree(node, this); |
117 120 | } |