Search in sources :

Example 56 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project head by mifos.

the class GroupRESTController method createGroupMapping.

private ObjectMapper createGroupMapping() {
    ObjectMapper om = new ObjectMapper();
    om.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
    om.getDeserializationConfig().addMixInAnnotations(CreateGroupCreationDetailDto.class, CreateGroupCreationDetailDtoMixIn.class);
    om.getDeserializationConfig().addMixInAnnotations(CreationAddresDto.class, CreationAddresDtoMixIn.class);
    om.getDeserializationConfig().addMixInAnnotations(CreationFeeDto.class, CreationFeeDtoMixIn.class);
    om.getDeserializationConfig().addMixInAnnotations(CreationMeetingDto.class, CreationMeetingDtoMixIn.class);
    om.getJsonFactory().configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS, true);
    return om;
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 57 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project head by mifos.

the class LoanAccountRESTController method createLoanAccount.

@RequestMapping(value = "/account/loan/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createLoanAccount(@RequestBody String request) throws Throwable {
    ObjectMapper om = createLoanAccountMapping();
    Map<String, String> map = new HashMap<String, String>();
    CreationLoanAccountDto creationDetails = null;
    try {
        creationDetails = om.readValue(request, CreationLoanAccountDto.class);
    } catch (JsonMappingException e) {
        e.getCause();
    }
    loanValidator(creationDetails);
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    LoanCreationResultDto loanResult = null;
    LoanBO loanInfo = null;
    CreateLoanAccount loanAccount = createLoan(creationDetails);
    if (creationDetails.getGlim()) {
        List<GroupMemberAccountDto> memberAccounts = creationDetails.glimsAsGroupMemberAccountDto(creationDetails.getGlimAccounts());
        CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, creationDetails.getLoanAmount(), loanAccount);
        loanResult = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, questionGroups, null);
        List<LoanBO> individuals = loanDao.findIndividualLoans(loanResult.getAccountId());
        for (int i = 0; i < individuals.size(); i++) {
            map.put("individualCustomer[" + i + "]", individuals.get(i).getCustomer().getDisplayName());
            map.put("individualAccount[" + i + "]", individuals.get(i).getGlobalAccountNum());
            map.put("individualAmmount[" + i + "]", individuals.get(i).getLoanAmount().toString());
        }
    } else {
        loanResult = loanAccountServiceFacade.createLoan(loanAccount, questionGroups, null);
    }
    loanInfo = loanDao.findByGlobalAccountNum(loanResult.getGlobalAccountNum());
    map.put("status", "success");
    map.put("accountNum", loanInfo.getGlobalAccountNum());
    map.put("GLIM", creationDetails.getGlim().toString());
    map.put("customer", loanInfo.getCustomer().getDisplayName());
    map.put("loanAmmount", loanInfo.getLoanAmount().toString());
    map.put("noOfInstallments", loanInfo.getNoOfInstallments().toString());
    map.put("externalId", loanInfo.getExternalId());
    return map;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) GroupMemberAccountDto(org.mifos.clientportfolio.newloan.applicationservice.GroupMemberAccountDto) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto) CreateGlimLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CreationLoanAccountDto(org.mifos.application.servicefacade.CreationLoanAccountDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 58 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project head by mifos.

the class LoanAccountRESTController method createLoanAccountMapping.

private ObjectMapper createLoanAccountMapping() {
    ObjectMapper om = new ObjectMapper();
    om.getJsonFactory().configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS, true);
    om.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
    om.getDeserializationConfig().addMixInAnnotations(CreationLoanAccountDto.class, CreationLoanAccountDtoMixIn.class);
    om.getDeserializationConfig().addMixInAnnotations(CreationFeeDto.class, CreationFeeDtoMixIn.class);
    om.getDeserializationConfig().addMixInAnnotations(CreationAccountPenaltyDto.class, CreationAccountPenaltyDtoMixIn.class);
    om.getDeserializationConfig().addMixInAnnotations(CreationGLIMAccountsDto.class, CreationGLIMAccountsDtoMixIn.class);
    return om;
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 59 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project head by mifos.

the class RESTApprovalEntity method getApprovalMethod.

@Transient
public ApprovalMethod getApprovalMethod() throws Exception {
    if (approvalMethod == null) {
        ObjectMapper om = new ObjectMapper();
        approvalMethod = om.readValue(getMethodContent(), ApprovalMethod.class);
    }
    return approvalMethod;
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Transient(javax.persistence.Transient)

Example 60 with ObjectMapper

use of org.codehaus.jackson.map.ObjectMapper in project head by mifos.

the class CollectionsheetRESTAPITest method verifyCollectionSheet.

@SuppressWarnings("PMD.SignatureDeclareThrowsException")
@Test
public void verifyCollectionSheet() throws Exception {
    String type = Type.CENTER_COLLECTIONSHEET;
    String by = By.ID;
    String value = CENTER_ID;
    String actualJSON = helper.getJSONFromUI(type, by, value);
    String expectedJSON = helper.getJSONFromDataSet(type, by, value);
    ObjectMapper mapper = helper.getObjectMapper();
    Assert.assertEquals(mapper.readTree(expectedJSON), mapper.readTree(actualJSON));
    String saveCollectionsheetJSON = getTestSaveCollectionsheetJSON();
    actualJSON = helper.postJSONFromUI("collectionsheet/save.json", saveCollectionsheetJSON);
    expectedJSON = getSumitCollectionSheetResponse();
    Assert.assertEquals(mapper.readTree(expectedJSON), mapper.readTree(actualJSON));
    actualJSON = helper.getJSONFromUI(type, by, value);
    expectedJSON = getEmptyCollectionsheet();
    Assert.assertEquals(mapper.readTree(expectedJSON), mapper.readTree(actualJSON));
    dateTimeUpdaterRemoteTestingService.setDateTime(new DateTime(2011, 9, 13, 13, 0, 0, 0));
}
Also used : ObjectMapper(org.codehaus.jackson.map.ObjectMapper) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)386 IOException (java.io.IOException)85 Test (org.junit.Test)61 JsonNode (org.codehaus.jackson.JsonNode)50 HashMap (java.util.HashMap)46 ArrayList (java.util.ArrayList)45 Test (org.testng.annotations.Test)37 Map (java.util.Map)34 List (java.util.List)26 File (java.io.File)22 StringWriter (java.io.StringWriter)22 JSONObject (org.json.JSONObject)18 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)17 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 Version (org.codehaus.jackson.Version)14 JsonFactory (org.codehaus.jackson.JsonFactory)13 JSONObject (org.codehaus.jettison.json.JSONObject)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 JsonGenerator (org.codehaus.jackson.JsonGenerator)11