tidy up json serialization for loan account areas.

This commit is contained in:
Keith Woodlock
2012-07-22 12:48:14 +01:00
parent 2a4d7335cb
commit 36ea860dfc
7 changed files with 216 additions and 142 deletions
@@ -1,6 +1,9 @@
package org.mifosng.platform.api; package org.mifosng.platform.api;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@@ -28,12 +31,12 @@ import org.mifosng.platform.api.data.LoanAccountSummaryData;
import org.mifosng.platform.api.data.LoanBasicDetailsData; import org.mifosng.platform.api.data.LoanBasicDetailsData;
import org.mifosng.platform.api.data.LoanPermissionData; import org.mifosng.platform.api.data.LoanPermissionData;
import org.mifosng.platform.api.data.LoanRepaymentPeriodData; import org.mifosng.platform.api.data.LoanRepaymentPeriodData;
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
import org.mifosng.platform.api.data.LoanSchedule; import org.mifosng.platform.api.data.LoanSchedule;
import org.mifosng.platform.api.data.LoanTransactionData; import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.LoanRepaymentTransactionData;
import org.mifosng.platform.api.data.NewLoanData; import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService; import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException; import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
import org.mifosng.platform.loan.service.CalculationPlatformService; import org.mifosng.platform.loan.service.CalculationPlatformService;
import org.mifosng.platform.loan.service.LoanReadPlatformService; import org.mifosng.platform.loan.service.LoanReadPlatformService;
@@ -47,14 +50,6 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class LoansApiResource { public class LoansApiResource {
private String filterName = "myFilter";
private String allowedFieldList = "";
private String loanFilterName = "loanFilter";
private String loanAllowedFieldList = "";
private String loanRepaymentFilterName = "loanRepaymentFilter";
private String loanRepaymentDefaultFieldList = "transactionType,date,total";
private String loanRepaymentAllowedFieldList = "";
@Autowired @Autowired
private LoanReadPlatformService loanReadPlatformService; private LoanReadPlatformService loanReadPlatformService;
@@ -67,9 +62,6 @@ public class LoansApiResource {
@Autowired @Autowired
private ApiDataConversionService apiDataConversionService; private ApiDataConversionService apiDataConversionService;
@Autowired
private ApiJSONFormattingService jsonFormattingService;
@GET @GET
@Path("template") @Path("template")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@@ -78,14 +70,19 @@ public class LoansApiResource {
@QueryParam("clientId") final Long clientId, @QueryParam("clientId") final Long clientId,
@QueryParam("productId") final Long productId, @QueryParam("productId") final Long productId,
@Context final UriInfo uriInfo) { @Context final UriInfo uriInfo) {
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("clientId", "clientName", "productId", "productName",
"selectedProduct", "expectedDisbursementDate", "allowedProducts"));
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
if (responseParameters.isEmpty()) {
responseParameters.addAll(typicalResponseParameters);
}
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
NewLoanData workflowData = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId);
NewLoanData workflowData = this.loanReadPlatformService return this.apiDataConversionService.convertNewLoanDataToJson(prettyPrint, responseParameters, workflowData);
.retrieveClientAndProductDetails(clientId, productId);
String selectedFields = "";
return this.jsonFormattingService.convertRequest(workflowData,
filterName, allowedFieldList, selectedFields,
uriInfo.getQueryParameters());
} }
@GET @GET
@@ -96,32 +93,36 @@ public class LoansApiResource {
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@Context final UriInfo uriInfo) { @Context final UriInfo uriInfo) {
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService Set<String> typicalResponseParameters = new HashSet<String>(
.retrieveLoanAccountDetails(loanId); Arrays.asList("id", "externalId", "fundId", "fundName", "loanProductId", "loanProductName", "principal", "inArrearsTolerance", "numberOfRepayments",
"repaymentEvery", "interestRatePerPeriod", "annualInterestRate",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
"submittedOnDate", "approvedOnDate", "expectedDisbursementDate", "actualDisbursementDate",
"expectedFirstRepaymentOnDate", "interestChargedFromDate", "closedOnDate", "expectedMaturityDate",
"lifeCycleStatusId", "lifeCycleStatusText", "lifeCycleStatusDate",
"summary", "repaymentSchedule", "loanRepayments", "permissions", "convenienceData")
);
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
if (responseParameters.isEmpty()) {
responseParameters.addAll(typicalResponseParameters);
}
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
Collection<LoanRepaymentTransactionData> loanRepayments = this.loanReadPlatformService Collection<LoanRepaymentTransactionData> loanRepayments = this.loanReadPlatformService.retrieveLoanPayments(loanId);
.retrieveLoanPayments(loanId); Collection<LoanRepaymentPeriodData> repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId);
Collection<LoanRepaymentPeriodData> repaymentSchedule = this.loanReadPlatformService
.retrieveRepaymentSchedule(loanId);
LoanAccountSummaryData summary = this.loanReadPlatformService LoanAccountSummaryData summary = this.loanReadPlatformService.retrieveSummary(loanBasicDetails.getPrincipal(), repaymentSchedule, loanRepayments);
.retrieveSummary(loanBasicDetails.getPrincipal(),
repaymentSchedule, loanRepayments);
LoanPermissionData permissions = this.loanReadPlatformService LoanPermissionData permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails,
.retrieveLoanPermissions(loanBasicDetails, summary summary.isWaiveAllowed(loanBasicDetails.getInArrearsTolerance()),
.isWaiveAllowed(loanBasicDetails loanRepayments.size());
.getInArrearsTolerance()), loanRepayments
.size());
LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, summary, repaymentSchedule, loanRepayments, permissions);
summary, repaymentSchedule, loanRepayments, permissions);
return this.apiDataConversionService.convertLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
String selectedFields = "";
String associatedFields = "summary,repaymentSchedule,loanRepayments,permissions,convenienceData";
return this.jsonFormattingService.convertRequest(loanAccount,
loanFilterName, loanAllowedFieldList, selectedFields,
associatedFields, uriInfo.getQueryParameters());
} }
@POST @POST
@@ -261,28 +262,27 @@ public class LoansApiResource {
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@QueryParam("command") final String commandParam, @QueryParam("command") final String commandParam,
@Context final UriInfo uriInfo) { @Context final UriInfo uriInfo) {
String json = ""; Set<String> typicalResponseParameters = new HashSet<String>(
String selectedFields = loanRepaymentDefaultFieldList; Arrays.asList("id", "transactionType", "date", "principal", "interest", "total", "totalWaived", "overpaid")
if (is(commandParam, "repayment")) { );
LoanTransactionData loanRepaymentData = this.loanReadPlatformService
.retrieveNewLoanRepaymentDetails(loanId); Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
json = this.jsonFormattingService.convertRequest(loanRepaymentData, if (responseParameters.isEmpty()) {
loanRepaymentFilterName, loanRepaymentAllowedFieldList, responseParameters.addAll(typicalResponseParameters);
selectedFields, uriInfo.getQueryParameters());
} else if (is(commandParam, "waiver")) {
LoanTransactionData loanWaiverData = this.loanReadPlatformService
.retrieveNewLoanWaiverDetails(loanId);
json = this.jsonFormattingService.convertRequest(loanWaiverData,
loanRepaymentFilterName, loanRepaymentAllowedFieldList,
selectedFields, uriInfo.getQueryParameters());
} }
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
if (StringUtils.isBlank(json)) {
LoanTransactionData transactionData = null;
if (is(commandParam, "repayment")) {
transactionData = this.loanReadPlatformService.retrieveNewLoanRepaymentDetails(loanId);
} else if (is(commandParam, "waiver")) {
transactionData = this.loanReadPlatformService.retrieveNewLoanWaiverDetails(loanId);
} else {
throw new UnrecognizedQueryParamException("command", commandParam); throw new UnrecognizedQueryParamException("command", commandParam);
} }
return json; return this.apiDataConversionService.convertLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
} }
@GET @GET
@@ -292,14 +292,20 @@ public class LoansApiResource {
public String retrieveTransaction(@PathParam("loanId") final Long loanId, public String retrieveTransaction(@PathParam("loanId") final Long loanId,
@PathParam("transactionId") final Long transactionId, @PathParam("transactionId") final Long transactionId,
@Context final UriInfo uriInfo) { @Context final UriInfo uriInfo) {
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "transactionType", "date", "principal", "interest", "total", "totalWaived", "overpaid")
);
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
if (responseParameters.isEmpty()) {
responseParameters.addAll(typicalResponseParameters);
}
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
LoanTransactionData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
LoanTransactionData loanRepaymentData = this.loanReadPlatformService return this.apiDataConversionService.convertLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
.retrieveLoanTransactionDetails(loanId, transactionId);
String selectedFields = loanRepaymentDefaultFieldList;
return this.jsonFormattingService.convertRequest(loanRepaymentData,
loanRepaymentFilterName, loanRepaymentAllowedFieldList,
selectedFields, uriInfo.getQueryParameters());
} }
@POST @POST
@@ -3,10 +3,8 @@ package org.mifosng.platform.api.data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collection; import java.util.Collection;
import org.codehaus.jackson.map.annotate.JsonFilter;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
@JsonFilter("loanFilter")
public class LoanAccountData { public class LoanAccountData {
private Long id; private Long id;
@@ -2,25 +2,22 @@ package org.mifosng.platform.api.data;
public class LoanPermissionData { public class LoanPermissionData {
private boolean waiveAllowed; private final boolean waiveAllowed;
private boolean makeRepaymentAllowed; private final boolean makeRepaymentAllowed;
private boolean rejectAllowed; private final boolean rejectAllowed;
private boolean withdrawnByApplicantAllowed; private final boolean withdrawnByApplicantAllowed;
private boolean undoApprovalAllowed; private final boolean undoApprovalAllowed;
private boolean disbursalAllowed; private final boolean disbursalAllowed;
private boolean undoDisbursalAllowed; private final boolean undoDisbursalAllowed;
private boolean pendingApproval; private final boolean pendingApproval;
private boolean waitingForDisbursal; private final boolean waitingForDisbursal;
private final boolean anyActionOnLoanAllowed;
protected LoanPermissionData() { public LoanPermissionData(final boolean waiveAllowed,
// final boolean makeRepaymentAllowed, final boolean rejectAllowed,
} final boolean withdrawnByApplicantAllowed, final boolean undoApprovalAllowed,
final boolean undoDisbursalAllowed, final boolean disbursalAllowed, final boolean pendingApproval, final boolean waitingForDisbursal) {
public LoanPermissionData(boolean waiveAllowed,
boolean makeRepaymentAllowed, boolean rejectAllowed,
boolean withdrawnByApplicantAllowed, boolean undoApprovalAllowed,
boolean undoDisbursalAllowed, boolean disbursalAllowed, boolean pendingApproval, boolean waitingForDisbursal) {
this.waiveAllowed = waiveAllowed; this.waiveAllowed = waiveAllowed;
this.makeRepaymentAllowed = makeRepaymentAllowed; this.makeRepaymentAllowed = makeRepaymentAllowed;
this.rejectAllowed = rejectAllowed; this.rejectAllowed = rejectAllowed;
@@ -30,81 +27,46 @@ public class LoanPermissionData {
this.disbursalAllowed = disbursalAllowed; this.disbursalAllowed = disbursalAllowed;
this.pendingApproval = pendingApproval; this.pendingApproval = pendingApproval;
this.waitingForDisbursal = waitingForDisbursal; this.waitingForDisbursal = waitingForDisbursal;
} this.anyActionOnLoanAllowed = isRejectAllowed() || isWithdrawnByApplicantAllowed() || isPendingApproval() || isUndoDisbursalAllowed() || isMakeRepaymentAllowed();
public boolean isAnyActionOnLoanAllowed() {
return isRejectAllowed() || isWithdrawnByApplicantAllowed() || isPendingApproval() || isUndoDisbursalAllowed() || isMakeRepaymentAllowed();
} }
public boolean isWaiveAllowed() { public boolean isWaiveAllowed() {
return waiveAllowed; return waiveAllowed;
} }
public void setWaiveAllowed(boolean waiveAllowed) {
this.waiveAllowed = waiveAllowed;
}
public boolean isMakeRepaymentAllowed() { public boolean isMakeRepaymentAllowed() {
return makeRepaymentAllowed; return makeRepaymentAllowed;
} }
public void setMakeRepaymentAllowed(boolean makeRepaymentAllowed) {
this.makeRepaymentAllowed = makeRepaymentAllowed;
}
public boolean isRejectAllowed() { public boolean isRejectAllowed() {
return rejectAllowed; return rejectAllowed;
} }
public void setRejectAllowed(boolean rejectAllowed) {
this.rejectAllowed = rejectAllowed;
}
public boolean isWithdrawnByApplicantAllowed() { public boolean isWithdrawnByApplicantAllowed() {
return withdrawnByApplicantAllowed; return withdrawnByApplicantAllowed;
} }
public void setWithdrawnByApplicantAllowed(boolean withdrawnByApplicantAllowed) {
this.withdrawnByApplicantAllowed = withdrawnByApplicantAllowed;
}
public boolean isUndoApprovalAllowed() { public boolean isUndoApprovalAllowed() {
return undoApprovalAllowed; return undoApprovalAllowed;
} }
public void setUndoApprovalAllowed(boolean undoApprovalAllowed) {
this.undoApprovalAllowed = undoApprovalAllowed;
}
public boolean isDisbursalAllowed() { public boolean isDisbursalAllowed() {
return disbursalAllowed; return disbursalAllowed;
} }
public void setDisbursalAllowed(boolean disbursalAllowed) {
this.disbursalAllowed = disbursalAllowed;
}
public boolean isPendingApproval() {
return pendingApproval;
}
public void setPendingApproval(boolean pendingApproval) {
this.pendingApproval = pendingApproval;
}
public boolean isWaitingForDisbursal() {
return waitingForDisbursal;
}
public void setWaitingForDisbursal(boolean waitingForDisbursal) {
this.waitingForDisbursal = waitingForDisbursal;
}
public boolean isUndoDisbursalAllowed() { public boolean isUndoDisbursalAllowed() {
return undoDisbursalAllowed; return undoDisbursalAllowed;
} }
public void setUndoDisbursalAllowed(boolean undoDisbursalAllowed) { public boolean isPendingApproval() {
this.undoDisbursalAllowed = undoDisbursalAllowed; return pendingApproval;
}
public boolean isWaitingForDisbursal() {
return waitingForDisbursal;
}
public boolean isAnyActionOnLoanAllowed() {
return anyActionOnLoanAllowed;
} }
} }
@@ -1,13 +1,7 @@
package org.mifosng.platform.api.data; package org.mifosng.platform.api.data;
import org.codehaus.jackson.map.annotate.JsonFilter;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
/**
* TODO - KW - Think this is deprecated now.
*/
@Deprecated
@JsonFilter("loanRepaymentFilter")
public class LoanTransactionData { public class LoanTransactionData {
private Long id; private Long id;
@@ -1,14 +1,11 @@
package org.mifosng.platform.api.data; package org.mifosng.platform.api.data;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.codehaus.jackson.map.annotate.JsonFilter;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
@JsonFilter("myFilter") public class NewLoanData {
public class NewLoanData implements Serializable {
private Long clientId; private Long clientId;
private String clientName; private String clientName;
@@ -20,7 +20,10 @@ import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData; import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ConfigurationData; import org.mifosng.platform.api.data.ConfigurationData;
import org.mifosng.platform.api.data.FundData; import org.mifosng.platform.api.data.FundData;
import org.mifosng.platform.api.data.LoanAccountData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.NoteData;
import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeData;
import org.mifosng.platform.api.data.OfficeTransactionData; import org.mifosng.platform.api.data.OfficeTransactionData;
@@ -48,6 +51,12 @@ public interface ApiDataConversionService {
String convertNoteDataToJson(boolean prettyPrint, Set<String> responseParameters, NoteData... notes); String convertNoteDataToJson(boolean prettyPrint, Set<String> responseParameters, NoteData... notes);
String convertLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanProductData... products); String convertLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanProductData... products);
String convertNewLoanDataToJson(boolean prettyPrint, Set<String> responseParameters, NewLoanData newLoanData);
String convertLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
String convertLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData... transactions);
// //
FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json); FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json);
@@ -37,7 +37,10 @@ import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData; import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ConfigurationData; import org.mifosng.platform.api.data.ConfigurationData;
import org.mifosng.platform.api.data.FundData; import org.mifosng.platform.api.data.FundData;
import org.mifosng.platform.api.data.LoanAccountData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NewLoanData;
import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.NoteData;
import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeData;
import org.mifosng.platform.api.data.OfficeTransactionData; import org.mifosng.platform.api.data.OfficeTransactionData;
@@ -68,6 +71,111 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
gsonConverter = new Gson(); gsonConverter = new Gson();
} }
@Override
public String convertLoanTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final LoanTransactionData... transactions) {
Set<String> supportedParameters = new HashSet<String>(
Arrays.asList("id", "transactionType", "date", "principal", "interest", "total", "totalWaived", "overpaid")
);
final Set<String> parameterNamesToSkip = new HashSet<String>();
if (!responseParameters.isEmpty()) {
if (!supportedParameters.containsAll(responseParameters)) {
throw new UnsupportedParameterException(new ArrayList<String>(responseParameters));
}
parameterNamesToSkip.addAll(supportedParameters);
parameterNamesToSkip.removeAll(responseParameters);
}
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
if (prettyPrint) {
builder.setPrettyPrinting();
}
Gson gsonDeserializer = builder.create();
String json = "";
if (transactions != null && transactions.length == 1) {
json = gsonDeserializer.toJson(transactions[0]);
} else {
json = gsonDeserializer.toJson(transactions);
}
return json;
}
@Override
public String convertLoanAccountDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final LoanAccountData loanAccount) {
Set<String> supportedParameters = new HashSet<String>(
Arrays.asList("id", "externalId", "fundId", "fundName", "loanProductId", "loanProductName", "principal", "inArrearsTolerance", "numberOfRepayments",
"repaymentEvery", "interestRatePerPeriod", "annualInterestRate",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
"submittedOnDate", "approvedOnDate", "expectedDisbursementDate", "actualDisbursementDate",
"expectedFirstRepaymentOnDate", "interestChargedFromDate", "closedOnDate", "expectedMaturityDate",
"lifeCycleStatusId", "lifeCycleStatusText", "lifeCycleStatusDate",
"summary", "repaymentSchedule", "loanRepayments", "permissions", "convenienceData")
);
final Set<String> parameterNamesToSkip = new HashSet<String>();
if (!responseParameters.isEmpty()) {
if (!supportedParameters.containsAll(responseParameters)) {
throw new UnsupportedParameterException(new ArrayList<String>(responseParameters));
}
parameterNamesToSkip.addAll(supportedParameters);
parameterNamesToSkip.removeAll(responseParameters);
}
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
if (prettyPrint) {
builder.setPrettyPrinting();
}
Gson gsonDeserializer = builder.create();
return gsonDeserializer.toJson(loanAccount);
}
@Override
public String convertNewLoanDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final NewLoanData newLoanData) {
Set<String> supportedParameters = new HashSet<String>(
Arrays.asList("clientId", "clientName", "productId", "productName",
"selectedProduct", "expectedDisbursementDate", "allowedProducts")
);
final Set<String> parameterNamesToSkip = new HashSet<String>();
if (!responseParameters.isEmpty()) {
if (!supportedParameters.containsAll(responseParameters)) {
throw new UnsupportedParameterException(new ArrayList<String>(responseParameters));
}
parameterNamesToSkip.addAll(supportedParameters);
parameterNamesToSkip.removeAll(responseParameters);
}
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
if (prettyPrint) {
builder.setPrettyPrinting();
}
Gson gsonDeserializer = builder.create();
return gsonDeserializer.toJson(newLoanData);
}
@Override @Override
public String convertLoanProductDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final LoanProductData... products) { public String convertLoanProductDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final LoanProductData... products) {
Set<String> supportedParameters = new HashSet<String>( Set<String> supportedParameters = new HashSet<String>(