}
}
public ProcessConfig toObject(String json) {
if (json == null) {
return new ProcessConfig();
}
try {
// decode from JSON
ProcessConfig processConfig = mapper.readValue(json, ProcessConfig.class);
// decode Base64 encoded fields
if (processConfig.getComment() != null) {
byte[] bytes = processConfig.getComment().getBytes();
processConfig.setComment(new String(Base64.decodeBase64(bytes)));
}
if (processConfig.getMessages() != null) {
for (String langCode : processConfig.getMessages().keySet()) {
String msg = processConfig.getMessages().get(langCode);
if (msg != null) {
byte[] bytes = msg.getBytes(MESSAGES_CHARSET);
msg = new String(Base64.decodeBase64(bytes), MESSAGES_CHARSET);
processConfig.getMessages().put(langCode, msg);
}
}
}
if (processConfig.getDictionary() != null) {
byte[] codedDictionaryInBytes = processConfig.getDictionary().getBytes();
processConfig.setDictionary(new String(Base64.decodeBase64(codedDictionaryInBytes)));
}
return processConfig;
} catch (IOException e) {
throw new RuntimeException("Failed to read ProcessConfig from JSON", e);