Browse Source

Merge pull request #10100 from livk-cloud/fix-file-not-found

fix: fixed the error that the file could not be found after packing
pull/11617/head
Andrew Shvayka 2 years ago
committed by GitHub
parent
commit
73921e5480
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      application/src/main/java/org/thingsboard/server/service/mail/DefaultTbMailConfigTemplateService.java
  2. 10
      common/util/src/main/java/org/thingsboard/common/util/JacksonUtil.java

2
application/src/main/java/org/thingsboard/server/service/mail/DefaultTbMailConfigTemplateService.java

@ -32,7 +32,7 @@ public class DefaultTbMailConfigTemplateService implements TbMailConfigTemplateS
@PostConstruct @PostConstruct
private void postConstruct() throws IOException { private void postConstruct() throws IOException {
mailConfigTemplates = JacksonUtil.toJsonNode(new ClassPathResource("/templates/mail_config_templates.json").getFile()); mailConfigTemplates = JacksonUtil.toJsonNode(new ClassPathResource("/templates/mail_config_templates.json").getInputStream());
} }
@Override @Override

10
common/util/src/main/java/org/thingsboard/common/util/JacksonUtil.java

@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.kv.KvEntry;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.nio.file.Files; import java.nio.file.Files;
@ -259,6 +260,15 @@ public class JacksonUtil {
} }
} }
public static JsonNode toJsonNode(InputStream value) {
try {
return value != null ? OBJECT_MAPPER.readTree(value) : null;
} catch (IOException e) {
throw new IllegalArgumentException("The given InputStream value: "
+ value + " cannot be transformed to a JsonNode", e);
}
}
public static ObjectNode newObjectNode() { public static ObjectNode newObjectNode() {
return newObjectNode(OBJECT_MAPPER); return newObjectNode(OBJECT_MAPPER);
} }

Loading…
Cancel
Save