bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

spec working in demo-jolt site but not working in java #1116

Open togaurav opened 2 years ago

togaurav commented 2 years ago

Hi, I am facing a strange issue, the spec I created is working on demo-jolt website but it's not transforming correct result when I use it in java, please suggest, below are the details:

spec: [ { "operation": "shift", "spec": { "#WAY": "InitiatedBy", "leadId": "LoanApplicationID", "loan": { "#Refinance Vehicle": "TransactionType.Auto.LoanType", "#Individual": "TransactionType.Auto.PurchaseFrom", "state": "TransactionType.Auto.State", "amountRequested": "TransactionType.Auto.LoanAmount", "loanTermRequestYear": "TransactionType.Auto.Term" }, "vehicle": { "make": "TransactionType.Auto.VehicleInfo.Make", "model": "TransactionType.Auto.VehicleInfo.MOdel", "year": "TransactionType.Auto.VehicleInfo.Year", "category": "TransactionType.Auto.VehicleInfo.Category" }, "borrowers": { "0": { "@(boolMapping.primaryBorrower)": "Borrower.IsPrimaryBorrower", "military": "Borrower.IsMilitary", "ficoScore": "Borrower.Fico", "name": "Borrower.BorrowerPersonalInformation.Name.FirstName", "gender": "Borrower.BorrowerPersonalInformation.Name.LastName", "dateOfBirth": "Borrower.BorrowerPersonalInformation.DateOfBirth", "emailAddress": "Borrower.BorrowerPersonalInformation.ContactInformation.Email", "phone": "Borrower.BorrowerPersonalInformation.ContactInformation.HomePhone", "address": { "0": { "addressType": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.ResidenceType", "employmentDurationMonth": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.BorrowerTimeAtResidence", "employmentDurationYear": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.UnitTimeAtResidence", "currentResidence": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.ResidenceIndicator", "": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.Address.Street", "city": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.Address.City", "state": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.Address.State", "postalCode": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.Address.PostalCode", "addressLine1": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.Address.StreetNumber", "addressLine2": "Borrower.BorrowerPersonalInformation.BorrowerResidence.BorrowerResidenceInformation.Address.StreetName" } }, "employment": { "employmentDurationMonth": "Borrower.BorrowerEmployment.TimeAtJob", "employmentId": "Borrower.BorrowerEmployment.UnitTimeAtJob", "employmentDurationYear": "Borrower.BorrowerEmployment.YearAtEmployment", "salaryFrequency": "Borrower.BorrowerEmployment.SalaryFrequency", "grossIncome": "Borrower.BorrowerEmployment.CurrentSalary", "employmentStatus": "Borrower.EmploymentStatus" }, "#No": "SelfEmployed" } } } } ]

input-json : {"lastModifiedDateTime":1641444430000,"leadId":1167,"isVerified":"Yes","leadStep":"Information pending","status":"Active","primarySource":"Insurance","secondarySource":"Refinance","parentLeadId":1167,"loan":{"createdUserId":5,"createdDateTime":1642073925000,"lastModifiedUserId":5,"lastModifiedDateTime":1642097312000,"loanId":7,"refinanceLeadId":1167,"leadVehicleId":722,"amountRequested":4000,"loanTermRequestMonth":0,"loanTermRequestYear":2,"state":"CA","status":"Active","completed":true},"borrowers":[{"createdUserId":5,"createdDateTime":1641444231000,"lastModifiedUserId":5,"lastModifiedDateTime":1642075174000,"borrowerId":1167,"refinanceLeadId":1167,"name":"Rony Rish","dateOfBirth":[2022,1,5],"emailAddress":"fsdfsf@gmail.com","gender":"Male","maritalStatus":"Married","ficoScore":422,"status":"Active","employment":{"createdUserId":5,"createdDateTime":1642071236000,"lastModifiedUserId":5,"lastModifiedDateTime":1642075160000,"employmentId":13,"refinanceborrowerId":1167,"employmentStatus":"Salaried","grossIncome":2342,"salaryFrequency":"Monthly","employmentDurationYear":3,"employmentDurationMonth":12,"status":"Active","completed":true},"address":[{"createdUserId":5,"createdDateTime":1641444231000,"lastModifiedUserId":5,"lastModifiedDateTime":1642071235000,"addressId":1160,"leadAddressId":1160,"addressType":"Home","addressLine1":"4701 Great America Pkwy","addressLine2":"42","city":"Santa Clara","state":"CA","postalCode":"95054","durationInMonth":6,"durationInYear":99,"refinanceBorrowerId":1167,"status":"Active","completed":true,"currentResidence":true}],"completed":true,"primaryBorrower":true,"military":false},{"createdUserId":5,"createdDateTime":1641997290000,"lastModifiedUserId":5,"lastModifiedDateTime":1641997290000,"borrowerId":1179,"refinanceLeadId":1167,"name":"vikas","dateOfBirth":[1988,8,8],"emailAddress":"vikas.shukla@way.com","gender":"Male","maritalStatus":"Married","ficoScore":600,"status":"Active","employment":{"createdUserId":5,"createdDateTime":1641997291000,"lastModifiedUserId":5,"lastModifiedDateTime":1641997291000,"employmentId":8,"refinanceborrowerId":1179,"employmentStatus":"Salaried","grossIncome":20000,"salaryFrequency":"Monthly","employmentDurationYear":11,"employmentDurationMonth":1,"status":"Active","completed":true},"address":[{"createdUserId":5,"createdDateTime":1641997290000,"lastModifiedUserId":5,"lastModifiedDateTime":1641997290000,"addressId":1178,"leadAddressId":1181,"addressType":"Home","addressLine1":"Venezia B-403","durationInMonth":3,"durationInYear":22,"refinanceBorrowerId":1179,"status":"Active","completed":true,"currentResidence":false}],"completed":true,"primaryBorrower":true,"military":true}],"vehicle":{"createdUserId":1052219,"createdDateTime":1641444246000,"lastModifiedUserId":5,"lastModifiedDateTime":1642074239000,"vehicleId":885,"leadId":1167,"leadVehicleId":722,"year":"2020","make":"ASTON MARTIN","model":"DB11 AMR","subModel":"","partialVIN":"FSDFDSFGDSFDSFDSF","annualMileage":"10001","vinFlag":"No","category":"Car","versionNo":1,"status":"Active","completed":false}}

demo-jolt output: { "InitiatedBy" : "WAY", "LoanApplicationID" : 1167, "TransactionType" : { "Auto" : { "LoanType" : "Refinance Vehicle", "PurchaseFrom" : "Individual", "State" : "CA", "LoanAmount" : 4000, "Term" : 2, "VehicleInfo" : { "Make" : "ASTON MARTIN", "MOdel" : "DB11 AMR", "Year" : "2020", "Category" : "Car" } } }, "SelfEmployed" : "No", "Borrower" : { "IsMilitary" : false, "Fico" : 422, "BorrowerPersonalInformation" : { "Name" : { "FirstName" : "Rony Rish", "LastName" : "Male" }, "DateOfBirth" : [ 2022, 1, 5 ], "ContactInformation" : { "Email" : "fsdfsf@gmail.com" }, "BorrowerResidence" : { "BorrowerResidenceInformation" : { "ResidenceType" : "Home", "ResidenceIndicator" : true, "Address" : { "City" : "Santa Clara", "State" : "CA", "PostalCode" : "95054", "StreetNumber" : "4701 Great America Pkwy", "StreetName" : "42" } } } }, "BorrowerEmployment" : { "TimeAtJob" : 12, "UnitTimeAtJob" : 13, "YearAtEmployment" : 3, "SalaryFrequency" : "Monthly", "CurrentSalary" : 2342 }, "EmploymentStatus" : "Salaried" } }

java-output: { "InitiatedBy" : "WAY" }

Java Code: ` Path schema = Paths.get("src", "test", "resources", "jolt-spec.json"); String schemaPath = schema.toFile().getAbsolutePath(); List chainrSpecJSON = JsonUtils.filepathToList(schemaPath); Chainr chainr = Chainr.fromSpec(chainrSpecJSON);

    System.out.println("Input Json " + inputson);
    Object transformedOutput = chainr.transform(inputson);
    System.out.println("Converted JSON ");
    System.out.println(JsonUtils.toPrettyJsonString((transformedOutput)));`