fix(config-core): write comments and name in writeTo, not serializeOneTo
All checks were successful
ci/woodpecker/push/docs Pipeline was successful
ci/woodpecker/push/jfmod Pipeline was successful

This commit is contained in:
Johannes Frohnmeyer 2024-05-10 09:05:32 +02:00
parent dddda8b92a
commit fe2808cf45
Signed by: Johannes
GPG Key ID: E76429612C2929F4

View File

@ -91,6 +91,12 @@ public interface EntryInfo<T> {
*/
default <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void writeTo(Writer writer, String translationPrefix) throws TEx, IllegalAccessException {
try {
String commentText = JfConfigSafe.TRANSLATION_SUPPLIER.apply(translationPrefix + getName() + ".tooltip");
if (commentText != null) writer.comment(commentText);
if (getValueType().isEnum()) {
writer.comment("Valid: [" + Arrays.stream(getValueType().asEnum().options()).map(Objects::toString).collect(Collectors.joining(", ")) + "]");
}
writer.name(getName());
serializeOneTo(getValue(), translationPrefix, writer);
} catch (MalformedDataException e) {
LibJf.LOGGER.error("Could not write " + getName(), e);
@ -102,14 +108,6 @@ public interface EntryInfo<T> {
}
default <TEx extends Exception, Writer extends SerializeWriter<TEx, Writer>> void serializeOneTo(T value, String translationPrefix, Writer writer) throws TEx, MalformedDataException {
String commentText;
if ((commentText = JfConfigSafe.TRANSLATION_SUPPLIER.apply(translationPrefix + getName() + ".tooltip")) != null) {
writer.comment(commentText);
}
if (getValueType().isEnum()) {
writer.comment("Valid: [" + Arrays.stream(getValueType().asEnum().options()).map(Objects::toString).collect(Collectors.joining(", ")) + "]");
}
writer.name(getName());
LibJf.MAPPER.getAdapter(getTypeToken()).serialize(value, writer);
}