-
Notifications
You must be signed in to change notification settings - Fork 2.4k
FINERACT-2564: Migrate template package from GSON to Jackson #5722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,9 @@ | |
| */ | ||
| package org.apache.fineract.template.domain; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
| import com.google.gson.JsonArray; | ||
| import com.google.gson.JsonElement; | ||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
|
|
@@ -90,14 +90,20 @@ public static Template fromJson(final JsonCommand command) { | |
| break; | ||
| } | ||
|
|
||
| final JsonArray array = command.arrayOfParameterNamed("mappers"); | ||
|
|
||
| final List<TemplateMapper> mappersList = new ArrayList<>(); | ||
|
|
||
| for (final JsonElement element : array) { | ||
| mappersList.add(new TemplateMapper(element.getAsJsonObject().get("mappersorder").getAsInt(), | ||
| element.getAsJsonObject().get("mapperskey").getAsString(), | ||
| element.getAsJsonObject().get("mappersvalue").getAsString())); | ||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed ObjectMapper is being instantiated in multiple places—should we consider reusing a shared instance (e.g., via Spring) for consistency and efficiency, or is this intentional for now? |
||
| final ObjectMapper objectMapper = new ObjectMapper(); | ||
| final JsonNode rootNode = objectMapper.readTree(command.json()); | ||
| final JsonNode mappersNode = rootNode.get("mappers"); | ||
| if (mappersNode != null && mappersNode.isArray()) { | ||
| for (final JsonNode element : mappersNode) { | ||
| mappersList.add(new TemplateMapper(element.get("mappersorder").asInt(), element.get("mapperskey").asText(), | ||
| element.get("mappersvalue").asText())); | ||
| } | ||
| } | ||
| } catch (final Exception e) { | ||
| throw new RuntimeException("Failed to parse template mappers from JSON", e); | ||
| } | ||
|
|
||
| return new Template(name, text, entity, type, mappersList); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,8 @@ | |
| */ | ||
| package org.apache.fineract.template.service; | ||
|
|
||
| import com.google.gson.JsonArray; | ||
| import com.google.gson.JsonElement; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
@@ -94,14 +94,21 @@ public CommandProcessingResult updateTemplate(final Long templateId, final JsonC | |
| } | ||
| template.setType(type); | ||
|
|
||
| final JsonArray array = command.arrayOfParameterNamed("mappers"); | ||
| final List<TemplateMapper> mappersList = new ArrayList<>(); | ||
| for (final JsonElement element : array) { | ||
| mappersList.add(new TemplateMapper(element.getAsJsonObject().get("mappersorder").getAsInt(), | ||
| element.getAsJsonObject().get("mapperskey").getAsString(), | ||
| element.getAsJsonObject().get("mappersvalue").getAsString())); | ||
| try { | ||
| final ObjectMapper objectMapper = new ObjectMapper(); | ||
| final JsonNode rootNode = objectMapper.readTree(command.json()); | ||
| final JsonNode mappersNode = rootNode.get("mappers"); | ||
| final List<TemplateMapper> mappersList = new ArrayList<>(); | ||
| if (mappersNode != null && mappersNode.isArray()) { | ||
| for (final JsonNode element : mappersNode) { | ||
| mappersList.add(new TemplateMapper(element.get("mappersorder").asInt(), element.get("mapperskey").asText(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For parsing the mappers array, would it make sense to leverage Jackson’s data binding (e.g., mapping directly to a List) instead of manual tree traversal, or is this intentional for now? |
||
| element.get("mappersvalue").asText())); | ||
| } | ||
| } | ||
| template.setMappers(mappersList); | ||
| } catch (final Exception e) { | ||
| throw new RuntimeException("Failed to parse template mappers from JSON", e); | ||
| } | ||
| template.setMappers(mappersList); | ||
|
|
||
| this.templateRepository.saveAndFlush(template); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JDBC URL change in build.gradle—should that be handled in a separate PR, since it’s not directly related to the JSON migration?